How to get the return value from gprolog in C?

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

How to get the return value from gprolog in C?

daveti
Hi there,

I am trying to call gprolog in my C code. Instead of getting the solutions, wonder if I could get the gprolog function output (true/false) directly in my C code. Below is the example:
Based on -
http://gprolog.univ-paris1.fr/manual/html_node/gprolog072.html

Given the pl file:
parent(bob,   mary).
parent(jane,  mary).
parent(mary,  peter).
parent(paul,  peter).
parent(peter, john).

anc(X, Y):-
        parent(X, Y).

anc(X, Z) :-
        parent(X, Y),
        anc(Y, Z).

I know how to retrieve the solution from anc(X,john). However, if the query is anc(bob,john), then how could I retrieve the return value (true) from the gprolog in my C code? I have gone thru gprolog.h for a while. But it seems there is not such a func used to get the return value...


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

Re: How to get the return value from gprolog in C?

emacstheviking
Dave,

I have written a fair bit if C code to extend gprolog BUT never called it from C but looking at that example, I am not sure I fully understand the question...

> I know how to retrieve the solution from anc(X,john). However, if the query
> is anc(bob,john), then how could I retrieve the return value (true) from the
> gprolog in my C code? I have gone thru gprolog.h for a while. But it seems
> there is not such a func used to get the return value…

The while(res) would seem to me to be what you are after… that is a cursor over the result set as it where and presumably returns NULL when there are no more answers available… that would seem to indicate then that the return value from Pl_Query_Call() is either “true” (non-NULL) or “false” NULL.

Is that perhaps what you meant?

Sean Charles.


_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: How to get the return value from gprolog in C?

emacstheviking
In reply to this post by daveti
Forgot to add… the code should probably be something like this (not tested) if you wanted to ask “anc(bob,john)”…

      Pl_Query_Begin(PL_TRUE);
      arg[0] = Pl_Mk_String(“bob");
      arg[1] = Pl_Mk_String(“john");
      res = Pl_Query_Call(func, 2, arg);

and then res will be NULL or NOT-NULL I guess to indicate true / false.


_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: How to get the return value from gprolog in C?

"Micha� Bieli�ski"
In reply to this post by daveti
Dnia 24 Listopada 2013, 00:29, N, daveti napisał:
> Hi there,
>
> I am trying to call gprolog in my C code. Instead of getting the
> solutions, wonder if I could get the gprolog function output
> (true/false) directly in my C code.

Yes.  Check return of Pl_Query_Call.

--
Michał Bieliński


_______________________________________________
Users-prolog mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/users-prolog
Reply | Threaded
Open this post in threaded view
|

Re: How to get the return value from gprolog in C?

daveti
Hi Sean, Michal,

Thank you for your quick response. It works! I thought the return value from query is for checking if the function call itself succeeds or not....Anyway, this is exactly what I need.

Thank you so much for your help!
-daveti
Reply | Threaded
Open this post in threaded view
|

Re: How to get the return value from gprolog in C?

emacstheviking
No problems, this list has helped me out enough times it’s nice to get something simple to answer for a change! LMAO

All the best,
Sean.


On 24 Nov 2013, at 18:55, daveti <[hidden email]> wrote:

> Hi Sean, Michal,
>
> Thank you for your quick response. It works! I thought the return value from
> query is for checking if the function call itself succeeds or not....Anyway,
> this is exactly what I need.
>
> Thank you so much for your help!
> -daveti
>
>
>
> --
> View this message in context: http://gnu-prolog.996310.n3.nabble.com/How-to-get-the-return-value-from-gprolog-in-C-tp1166p1172.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