[ Control | Reference Manual | Alphabetic Index ]

call(+GoalPrefix, ?Arg, ?...)

Call with any number of additional arguments
GoalPrefix
A callable term
Arg
An additional argument for Goal
...
Optional further additional arguments for Goal

Description

Call the goal formed by appending the additional argument Arg (and any further arguments given) to GoalPrefix. For example, the following calls are all equivalent and invoke p/2:

	call(p, 1, 2)
	call(p(1), 2)
	call(p(1,2) )
	
The maximum arity for call/N is the one indicated by get_flag(max_predicate_arity,N), and is at least 255.

These predicates are sensitive to their calling context module in the same way as call/1.

Implementation note: These predicates are materialised lazily the first time they are being invoked. They may therefore not show up with current_built_in/1, get_flag/3 or other similar access methods.

Fail Conditions

Fails if the called goal fails

Resatisfiable

Resatisfiable if the called goal is resatisfiable

Exceptions

(4) instantiation fault
GoalPrefix is not instantiated.
(5) type error
GoalPrefix is not an atom or a compound term.
(68) calling an undefined procedure
Constructed goal refers to an undefined predicate.

Examples

    ?- call(p, 1, 2, 3).
    calling an undefined procedure p(1, 2, 3) in module eclipse
    Abort

    ?- call(append(L, R), [1]).
    L = []
    R = [1]
    Yes (0.00s cpu, solution 1, maybe more)
    L = [1]
    R = []
    Yes (0.00s cpu, solution 2)

    ?- call(+(3), 4, X).
    X = 7
    Yes (0.00s cpu)


    % A typical use case
    filter(_, [], []).
    filter(Pred, [X|Xs], Ys) :-
        ( call(Pred, X) ->
            Ys = [X|Ys1],
            filter(Pred, Xs, Ys1)
        ;
            filter(Pred, Xs, Ys)
        ).

    ?- filter(atom, [1, a, 2, b, c], As).
    As = [a, b, c]
    Yes (0.03s cpu)
    ?- filter(integer, [1, a, 2, b, c], As).
    As = [1, 2]
    Yes (0.06s cpu)
    ?- filter(<(2), [5, 1, 4, 2, 3], Is).
    Is = [5, 4, 3]
    Yes (0.00s cpu)

See Also

call / 1, @ / 2, : / 2