Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!nntp.club.cc.cmu.edu!goldenapple.srv.cs.cmu.edu!das-news2.harvard.edu!fas-news.harvard.edu!oitnews.harvard.edu!news.dfci.harvard.edu!camelot.ccs.neu.edu!news.mathworks.com!worldnet.att.net!cbgw2.lucent.com!cbgw1.lucent.com!newshub.netnews.att.com!ulysses!akalice!baldy.research.att.com!user
From: pereira@research.att.com (Fernando Pereira)
Subject: Re: Mixing CProlog with C language
X-Nntp-Posting-Host: baldy.research.att.com
Message-ID: <pereira-0904972231390001@baldy.research.att.com>
Sender: news@research.att.com (netnews <9149-80593> 0112740)
Organization: AT&T Research
References: <1997Apr9.023540@winnie>
Date: Thu, 10 Apr 1997 02:31:39 GMT
Lines: 41

In article <1997Apr9.023540@winnie>, pmangin@cs.wmich.edu wrote:

>         I am working on a class project and I have to write a CProlog
>   module which calls external predicates written in C language. 
>         Could someone briefly explain the process of creating the library 
>   and loading it into the CProlog code. The version of CProlog on our 
>   system is 1.5. 
Best answer: use a more modern free Prolog, such as SWI-Prolog. C-Prolog
has not been updated in *thirteen* years, and it wasn't designed to be
conveniently extended with user-supplied C code.

If you really must change C-Prolog:

1. Choose a new builtin predicate number, and add an appropriate #define
for it in evalp.h.

2. Add a case for the new builtin to the big switch statement after
EvalPred: in main.c. To figure out how to handle predicate arguments,
imitate known builtin predicates such as tell/1 and telling/1.

3. Write the C code for the new builtin, and call it appropriately from
the case  code created in 2.

4. Add a stub

   mypred(A1,...,Ak) :- m.

to init.pl, where m is the number chosen in 1.

5. Add appropriate compilation and linking commands to Makefile

6. Remake C-Prolog binary

7. Remake C-Prolog's bootstrap file with 

      make startup

This is just a brief sketch. Again, I don't advise doing this, as it is
rather error-prone, undocumented and totally unsupported.

-- F
