SICStus Prolog offers both current_predicate/1 and current_predicate/2.
The manual page states:
current_predicate(?PredSpec)
Unifies PredSpec with a predicate specifications of the form Name/Arity.
current_predicate(?Name, ?Term)
Unifies Name with the name of a user-defined predicate, and Term with the most general term corresponding to that predicate.
They appear to have the same features: both predicates work for enumerating predicates, both work with modules.
The manual page comments:
current_predicate/1 is part of the ISO Prolog standard; current_predicate/2 is not.
Should I ever use current_predicate/2
in new (= non-legacy) code?
Short answer, no. Don't use it in new code.
The benefit of current_predicate/2
was to allow querying, using a predicate call template, if the predicate is defined, unlike current_predicate/1
. E.g.
...,
( current_predicate(_, foo(_, _)) ->
foo(A, B)
; ...
),
...
But you can often use instead the standard predicate_property/2
predicate, which takes a template as first argument.
P.S. The Logtalk linter will scream at you (and suggest a more standard alternative) if it finds you calling current_predicate/2
:-)