Newsgroups: comp.lang.prolog,comp.lang.c,comp.lang.c++
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!news.acsu.buffalo.edu!news.uoregon.edu!arclight.uoregon.edu!feed1.news.erols.com!howland.erols.net!EU.net!usenet2.news.uk.psi.net!uknet!usenet1.news.uk.psi.net!uknet!uknet!newsfeed.ed.ac.uk!hwcee!andrew
From: andrew@cee.hw.ac.uk (Andrew Dinn)
Subject: Re: How to communciate between prolog and c(++)
Message-ID: <Dz2AL3.AL9@cee.hw.ac.uk>
Followup-To: comp.lang.prolog,comp.lang.c,comp.lang.c++
Sender: news@cee.hw.ac.uk (News Administrator)
Organization: Dept of Computing and Electrical Engineering, Heriot-Watt University
X-Newsreader: TIN [version 1.2 PL2]
References: <gores-ya023180000910961438270001@news.rz.uni-ulm.de> <53gso1$lab@bcrkh13.bnr.ca>
Date: Thu, 10 Oct 1996 13:24:39 GMT
Lines: 29
Xref: glinda.oz.cs.cmu.edu comp.lang.prolog:16175 comp.lang.c:210282 comp.lang.c++:217991

: kp gores asked:

: >how do i run a prolog query from within c ??

Kaz Kylheku replied:
: system("prolog_interpreter <query_name>");

That's a really crummy piece of advice. Using system as outlined above
creates another process and does not allow the calling program to
provide input or retrieve and handle output. Furthermore, system is
not guaranteed to work on all Prologs or all platforms (never mind
work the same way).

If you have a good Prolog like Quintus you can link in the relevant
Prolog libraries and run Prolog within the same process as your C
program by making a library call. Otherwise, if you are on a Unix
machine then, rather than use "system", there are library and system
functions which you can call to run Prolog in a sub-process, feeding
input to and reading output from the sub-process via streams. Check
out the manual pages on fork, exec and/or popen fpr starters. On other
platforms other facilities might be available. It all depends very
much on the Prolog implementation and the platform you are running on.


Andrew Dinn
-----------
And though Earthliness forget you,
To the stilled Earth say:  I flow.
To the rushing water speak:  I am.
