Page 1 of 1

call/1-N behavior

Posted: Mon May 24, 2010 5:44 am
by loed
Hi, Paulo

First of all, I would like to thank you for this brilliant language. I really like the idea of object-oriented logic language for I'm a big fan of both Prolog and OOP. But it seems I need your help :(

I'm trying to port some of my old prolog applications to Logtalk, but eventually got stuck with call/1-N predicate. According to the reference manual, this predicate can be used to send goal as a message to an explicit object, but when I try to use smth like "call(Object::pred, arg1, arg2...argN)" in my code I'm getting this error:

Code: Select all

ERROR!!
     EXISTENCE ERROR- procedure (::)/3 is undefined, called from context  prolog:$call/4
                 Goal was user: ::(test,test,_1279)
What am I doing wrong?

Thanks.

Re: call/1-N behavior

Posted: Mon May 24, 2010 12:06 pm
by Paulo Moura
loed wrote:Hi, Paulo

First of all, I would like to thank you for this brilliant language.
Thanks :-)
loed wrote:I really like the idea of object-oriented logic language for I'm a big fan of both Prolog and OOP. But it seems I need your help :(

I'm trying to port some of my old prolog applications to Logtalk, but eventually got stuck with call/1-N predicate. According to the reference manual, this predicate can be used to send goal as a message to an explicit object, but when I try to use smth like "call(Object::pred, arg1, arg2...argN)" in my code I'm getting this error:

Code: Select all

ERROR!!
     EXISTENCE ERROR- procedure (::)/3 is undefined, called from context  prolog:$call/4
                 Goal was user: ::(test,test,_1279)
What am I doing wrong?
Nothing. call/1-N are both Prolog built-in predicates and Logtalk built-in methods. If you type the goal above at the top-level, you're calling the Prolog built-in predicate, which is not Logtalk-aware. The end result is that the Prolog implementation tries to extend the ::/2 with the additional arguments, instead of extending the message term that you're sending to an object. You can check the difference by typing instead:

Code: Select all

| ?- logtalk << call(object::pred, arg1, arg2...argN)
In some Prolog compilers, it would be possible to hack the built-in call/1-N predicates using goal_expansion/2 in order to make these predicates Logtalk-aware. Unfortunately, this is only possible for a small number of the Logtalk-compatible Prolog compilers. Nevertheless, note that this is only a top-level issue. call/1-N calls from within object and categories behave as expected.