PLOGHELP PROLOG_EVAL Kathryn Seifert August 1986
Evaluates a Prolog term as a POP-11 expression.
?- prolog_eval(Expr).
?- prolog_eval(Expr, X).
?- prolog_evaltrue(Expr).
Keywords: POP-11, mixed language programming, evaluation
In all its forms, 'prolog_eval' evaluates a Prolog term -Expr- as a
POP-11 expression, using the evaluation rules described below.
The goal
?- prolog_eval(Expr).
evaluates -Expr- for its side-effect only, so -Expr- must not return a
result. This goal always succeeds.
The goal
?- prolog_eval(Expr, X).
evaluates -Expr- and unifies its result with the term -X-. -Expr- must
return exactly one result: failure to do so is likely to cause a 'STACK
EMPTY' error.
The goal
?- prolog_evaltrue(Expr).
evaluates -Expr- and succeeds only if the result is non-false. Again,
-Expr- must return exactly one result, but in this case it is simply
tested and discarded.
The rules used for evaluating -Expr- are as follows (NB problems of
dereferencing are ignored here: see PLOGHELP * TERMSINPOP for more
information):
(a) A complex term or Prolog structure with the functor 'quote'
evaluates to the unchanged argument of the functor. For example:
?- prolog_eval(quote(member(a, [1, 2, a, 3])), X).
X = member(a, [1, 2, a, 3]) ?
yes
(b) A complex term or Prolog structure with any functor other than
'quote' evaluates to the VALOF of the functor (see HELP * VALOF)
applied to the result of evaluating the arguments. For example:
?- prolog_eval(length(hd([[1, 2, 3], [a, b, c]])), X).
X = 3 ?
yes
(c) A Prolog atom (with or without the functor 'quote') evaluates to
a POP-11 word. For example:
?- prolog_eval(foo, X), prolog_eval(isword(X), Y).
X = foo
Y = ?
yes
(d) Numbers, words, strings, and all other atomic objects evaluate
to themselves.
(e) A list evaluates to the list of its evaluated items. For
example:
?- prolog_eval([length([a, 3, 5, b, 6]), *(6, 97)], X).
X = [5, 582] ?
yes
(f) A variable evaluates to the result of evaluating its content.
For example:
?- X = ([hd([c, a, t]), lizard, *(5, 4)]),
prolog_eval(X, Z).
X = [hd([c, a, t]), lizard, 5 * 4]
Z = [c, lizard, 20] ?
yes
The predicate 'is/2' is simply a syntactic variant of 'prolog_eval/2',
so its evaluation rules are the same as those given here. 'is/2' could
be defined as:
X is Expr :-
prolog_eval(Expr, X).
There is also a library package, described in PLOGHELP * ARE, which
copes with expressions returning multiple results.
-- RELATED DOCUMENTATION ----------------------------------------------
HELP * VALOF
Explanation of the POP-11 procedure 'valof'
PLOGHELP * ARE
Library for evaluating POP-11 expressions with any number of results
PLOGHELP * IS
Evaluating POP-11 expressions which return 1 result from Prolog
PLOGHELP * MIXED_LANGUAGES
Overview of interface between Prolog and other languages
PLOGHELP * PLOGTOPOP
How to call POP-11 from Prolog
PLOGHELP * TERMSINPOP
Facilities for manipulating Prolog terms and variables in POP-11
--- C.all/plog/help/prolog_eval
--- Copyright University of Sussex 1988. All rights reserved. ----------