In sicstus prolog, there's a predicate:
maplist(:Pred, +List)
Pred
is supposed to take just one argument - List
element. How can I pass a 2-argument predicate, with first argument defined? In other languages it would be written as:
maplist(pred.bind(SomeValue), List)
maplist(P_1, Xs)
will callcall(P_1, X)
for each element ofXs
. The built-in predicatecall/2
adds one further argument toP_1
and then calls this withcall/1
. To indicate that a further argument is needed, it is very helpful to use a name likeP_1
meaning "one extra argument is needed".So if you have already a predicate of arity 2, say,
(=)/2
, you will pass=(2)
to maplist:Since the definition in SICStus' library is unfortunately incorrect, rather use the following definition:
See this answer for more.
Just a nice further example about lists of lists.