I'm using SWI-Prolog Version 6.4.1 on OS X 7, and am experiencing the following unexpected behavior with the predicate current_functor/2
:
Given the facts
p(a).
q.
I get these answers to queries:
?- current_functor(p, Y).
Y = 1
?- current_functor(q, Y).
false.
?- current_functor(q, 0).
true.
Not only do the second and third queries seem blatantly inconsistent, but the failure of the second doesn't seem consistent with the SWI-Prolog reference manual, which describes current_functor/2
as follows:
current_functor(?Name, ?Arity) Successively unifies Name with the name and Arity with the arity of functors known to the system.
Can anyone help me understand why the predicate is functioning in this way?
Edit:
In terms of solving my particular problem of testing whether or not predicates had been defined, including certain 0-arity ones, I ended up following false's advice and writing the following:
current_pred(P) :-
current_predicate(P/_).
swipl
version 6.0.2 on Linux. – lurkercurrent_predicate/1
instead? – Paulo Mouracurrent_predicate
appears consistent.current_predicate(p/Y).
yieldsY = 1
andcurrent_predicate(q/Y).
yieldsY = 0
as expected. – lurkercurrent_predicate(q/X)
succeeds, and is what I will use for my current project, although it doesn't answer the question. But are you suggesting thatcurrent_functor/2
has been depreciated in favor ofcurrent_predicate/1
? I doesn't say so in the manual... – Shoncurrent_functor/2
allows you to query both predicate and function functors. But, if you're only concerned about predicates, I expect that you could replace calls tocurrent_functor/2
with calls tocurrent_predicate/1
. – Paulo Moura