1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Rep Power

    execute Prolog from C program


    I was wondering how I can call a Prolog query from a C program.
    The Prolog compiler that I'm using is LPA's WinProlog and I'm using code warrior for the C code.
    I would like to be able to query the prolog code and get back a result.

    any ideas???
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Rep Power
    My immediate response is to tell you to read WinProlog's documentation for that. I say that, because such capabilities rely more on the implementation than on general language features. For example, my only prolog experience was with Borland's Turbo Prolog; Turbo Prolog could call C functions, but a C program could not call Turbo Prolog.

    I just did a quick Google on WinProlog and found this statement at http://www-lp.doc.ic.ac.uk/UserPages.../lpa/lpa1.html :
    DLL Interface. Allows Prolog to call, or be called by, programs written in C, Pascal, etc. Synchronous and asynchronous message passing is supported.
    So that tells me that it can be done. That's half the battle.

    At the company's website, http://www.lpa.co.uk/win_det.htm , I read:
    Direct Windows API Interface

    As well as providing high-level access to around 100 Windows API (Application Programming Interface) functions, not to mention numerous subfunctions, WIN-PROLOG includes a special interface which allows your programs to call virtually any C function directly, whether defined in the Windows API or in a DLL or other module. The winapi/3 predicate allows any function, defined in any 32-bit module, to be called with any number of parameters. The parameters may be integers, string pointers, or arbitrary structures, and facilities exist for defining named "memory files". All memory allocation and stack frame creation is carried out automatically, so your only job as a programmer is to provide the relevant data and call the function.

    The Windows API function means that your programs are no longer "limited" to using the 100-plus API functions built into WIN-PROLOG by LPA, but can add additional functions yourself as and when you need them. It also provides a direct way to invoke code in DLLs, without having to write parameter-translating ("glue") code in C/C++.
    So somewhere there has to be an API defined for that DLL and the only place I can think of would be in the documentation somewhere.

    Some of the messages in the comp.lang.prolog newsgroup mention WinProlog, so that might be a place to post your question as well. I usually access the newsgroups through Google. Google also has a search engine for the newsgroups, so you can search through past messages.
    Last edited by dwise1_aol; April 19th, 2003 at 11:53 AM.

IMN logo majestic logo threadwatch logo seochat tools logo