Returning functors

58 views
Skip to first unread message

mmxgn

unread,
Sep 9, 2010, 7:15:06 AM9/9/10
to pyswip
Hello,

I just explored pyswip and I think it's going to help me a lot.

One question is:

I have the following prolog code for addition:

{{{
plus(z, N, N).
plus(s(Mn), N, s(Pn)) :- plus(Mn, N, Pn).
s(N).
}}}

and the following pyswip equivalent

{{{
from pyswip import Prolog
prolog = Prolog()

prolog.assertz("plus(z, N, N)");
prolog.assertz("plus(s(Mn), N, s(Pn)) :- plus(Mn, N, Pn)")
prolog.assertz("s(N)")
}}}

When I query swipl on the first with
{{{
plus(s(z), s(z), X).
}}}

It gives me that X = s(s(z)) which is the correct answer.

When on the other hand I try in python:

{{{
print list(prolog.query("plus(s(z),s(z),X)"))
}}}

It prints:

[{'X': 'Functor5267596'}]

instead of s(s(z)).

Is there a way to make it show s(s(z)) instead of the string object
above? Or have I got something wrong?

Reply all
Reply to author
Forward
0 new messages