users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to add predicates to the gnu-prolog engine at runtime from C?


From: tvetunge
Subject: How to add predicates to the gnu-prolog engine at runtime from C?
Date: Wed, 19 Mar 2003 01:14:51 +0100


Hiya.


This question has been up before, almost. Only the answer presumed the 
predicates
in question were known at compile-time. This is not the case for me.

I want to write an environment (virtual world) with support for dynamic changes
of rules and facts of the environment while the environment is running.
Imagine one window where the intended user can move about and interact, and
one beside it where the rules are listed and can be changed.

For this I need a function like 
c_assert(  "at(tree,apple)."  );       
and 
c_retract(  "at(tree,apple)."  );

My problem in this is that I see no function in the c-interface supporting
this.
To be able to do it at all, it would seem I'd have to write my own prolog-parser
that then translates the predicates 

"assertz(<whatever-I-want>)." 
and 
"retract(<whatever-I-want>)." 

into PlTerms == WamWords == longs, which gnu-prolog uses for passing predicates
back and forth between engine and c.

For this I've been searching the sourcecode, in the hope that in there such
a parser were already present. It appears to be, but in Prolog, not C.. so
I have trouble reading it.

I am looking for a predicate that translates an input string to an output
WamWord.

If I had such a predicate, I could use a Pl_Query_Call to make use of it
like suggested by Vic Bancroft earlier. 
( http://mail.gnu.org/archive/html/users-prolog/2003-02/msg00019.html )

And then, with WamWord in hand, another query could be made that did what
I wanted.

It seems code_generation/5 in /src/Pl2Wam/code_gen.pl might do this, but
I'm not sure, and I don't know how to use it. My attempts failed :]

So what I'm basically looking for is information on which function in the
source that provides translation from string predicates to PlTerms as the
interface understands them.

Also ideas on how to tackle multiple-line assertions would be most welcome.
Many predicates are pretty long.


Regards, Uffe Wassmann.




________________________________________
Få din egen webmail på http://solmail.sol.dk - gratis og med dig overalt!
Træt af virus? Få gratis beskyttelse her: http://antivirus.sol.dk






reply via email to

[Prev in Thread] Current Thread [Next in Thread]