Is that possible to call dynamic function in the C interface?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Is that possible to call dynamic function in the C interface?

daveti
Hi there,

Dave is back again - with a weird question:)
Say we have a dynamic function in the pl file:
:- dynamic(parent/2).
Then there are some bindings too...
parent(bob,mary).
parent(mary,john).
In GProlog, asserta(parent(daveti,john)). will add a new binding. So, how could I make it using the C interface?
It looks like to me query function is not designed for calling dynamic function....Or am I wrong?
int Pl_Query_Call(int func, int arity, PlTerm *arg_adr);

Thanks,
Dave
Reply | Threaded
Open this post in threaded view
|

Re: Is that possible to call dynamic function in the C interface?

daveti
Hello guys,

Never mind - I have figured out the right way to do that:
1. Use Pl_Mk_Callable() construct the dynamic function - parent(daveti,john).
2. Use Pl_Find_Atom("asserta") to get the id for 'asserta'
3. Use Pl_Query_Call(id_of_asserta, 1, pterm_returned_by_callable).
Then magic will happen.

Cheers~
Dave
Reply | Threaded
Open this post in threaded view
|

Re: Is that possible to call dynamic function in the C interface?

emacstheviking
In reply to this post by daveti
Hi Dave,

Without having seen the source code my interpretation would be that Pl_Query_Call() would search the database and, irrespective of how a predicate/rule/fact arrived there, if it finds it, it will call it. Why would it not find a dynamic predicate? That wouldn't be very useful I don't think and, with what knowledge of gprolog internals I do have, having written some things myself, I'd be surprised if it didn't work with dynamic predicates.

The only way to find out though is to actually do it I guess, I don't have the time nor the inclination today!

Is your question really "How do I find out what predicates have been dynamically created?" in which case you would have to call current_predicate/0...here is part of the help text, I bolded the bit you might want to see!

current_predicate(Pred) succeeds if there exists a predicate indicator of a defined procedure that unifies with Pred. All user defined procedures are found, whether static or dynamic. Internal system procedures whose name begins with ’$’ are not found.

Hope that helps.
:)
Sean.



On 26 November 2013 21:24, daveti <[hidden email]> wrote:
Hi there,

Dave is back again - with a weird question:)
Say we have a dynamic function in the pl file:
:- dynamic(parent/2).
Then there are some bindings too...
parent(bob,mary).
parent(mary,john).
In GProlog, asserta(parent(daveti,john)). will add a new binding. So, how
could I make it using the C interface?
It looks like to me query function is not designed for calling dynamic
function....Or am I wrong?
int Pl_Query_Call(int func, int arity, PlTerm *arg_adr);

Thanks,
Dave



--
View this message in context: http://gnu-prolog.996310.n3.nabble.com/Is-that-possible-to-call-dynamic-function-in-the-C-interface-tp1177.html
Sent from the Users mailing list archive at Nabble.com.

_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog


_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog