call/N.

Ulrich Neumerkel 2009-09-20 (Version history)
This draft is based on Paulo Moura's draft core 8.15.4 N208 13211-1:2006 of 2008-11-17. It is being prepared for the second technical corrigendum of 13211-1:1995 and incorporates the following resolution of Pasadena, 2009.
A 2. WG 17 resolves that call/2-N of 8.15.4 in N 208 shall require all implementations to support at least an arity of 8 (allowing seven extra arguments). The exact number shall be implementation dependent, with errors determined by the resulting call to a possibly non existent predicate.
References refer to 13211-1:1995. Parts needing improvements are underlined.

TBD: control construct 7.8 vs. built-in 8.15 Logic and control.

8.15.4 call/2..8

NOTE — A built-in predicate apply/2 is implemented in many existing processors. In most uses it can be directly replaced by call/N. @@@

8.15.4.1 Description

call(C, Arg1, ...) is true iff call(Goal) is true where Goal is constructed by appending Arg1, ... additional arguments to the arguments (if any) of C. Thus, a goal call(p(X1,...,XM), Y2, ..., YN) is replaced by call(p(X1, ..., XM, Y2, ..., YN)).

8.15.4.2 Template and modes

call(+callable_term, ?term, ...)

8.15.4.3 Errors

a) C is a variable
instantiation error.
b) C is neither a variable nor a callable term
type_error(callable, C). (Remark: in other words C is a number).
c) The number of arguments in the resulting goal exceeds the implementation defined maximum arity (7.11.2.3)
representation_error(max_arity).
d) call/9 is called. It is implementation dependent whether or not this error is produced.
existence_error(procedure,call/9).
NOTE — Due to the error in subclause d being implementation dependent (3.91), a conforming processor may implement call/N in one of the following ways.
1) Implement only the seven built-in predicates call/2 up to call/8.
2) Implement call/2..N up to any N that is within 8..max_arity (7.11.2.3) and produce existence errors for larger arities below max_arity.
3) Implement call/9 and above only for certain execution modes.
Implementation dependence also means that it is neither required nor forbidden to define the chosen approach in the processor documentation (5.4).

8.15.4.4 Examples

call(integer, 3).
   Succeeds.

call(functor(F,c), 0).
   Succeeds, unifying F with c.

call(atom_concat(pro), log, Atom).
   Succeeds, unifying Atom with prolog.

call(;, X = 1, Y = 2).
   Succeeds, unifying  X with 1.  On backtracking,
   it succeeds, unifying Y with 2.

call(;, (true->fail), X=1).
   Fails.

The following examples assume that maplist/2
   is defined with the following clauses:


maplist(_Cont, []).
maplist(Cont, [E|Es]) :-
   call(Cont, E),
   maplist(Cont, Es).

maplist(<(3), [1,2]).
   Succeeds.

maplist(<(3), [1,2,3]).
   Fails.

maplist(=(X), Xs).
   Succeeds,
      unifying Xs with [].
   On re-execution, succeeds,
      unifying Xs with [X].
   On re-execution, succeeds,
      unifying Xs with [X,X].
   On re-execution, succeeds,
      unifying Xs with [X,X,X].
   Ad infinitum.

Validated HTML