PLOGHELP IS                                   Chris Mellish  August 1982
                                 Revised by Kathryn Seifert  August 1986

Evaluating POP-11 and arithmetic expressions which return one result

    ?- <prologvar:V> is <expression:E>

Keywords: POP-11, Prolog, arithmetic, mixed language programming,
          evaluation


CONTENTS - (Use <ENTER> g to access sections)

 -- INTRODUCTION
 -- USING 'IS' FOR ARITHMETIC
 -- USING 'IS' TO EVALUATE NON-ARITHMETIC POP-11 EXPRESSIONS
 -- PROLOG_EVAL
 -- RELATED DOCUMENTATION


-- INTRODUCTION -------------------------------------------------------

'is' is a built-in Prolog predicate which is declared as an infix
operator of precedence 40 and fix "xfx" (see PLOGHELP * OP).  Calls of
this predicate take the following form:

    ?- <prologvar:V> is <expression:E>

The expression E can be an arithmetic expression or other POP-11
expression. V becomes bound to the evaluation of E.  V may be initially
instantiated or uninstantiated, but E must be fully instantiated.


-- USING 'IS' FOR ARITHMETIC ------------------------------------------

If E is an arithmetic expression, then it may be an integer or a real
number, or it may be composed of numbers using the special functors:

    Expr1 * Expr2       - multiplication
    Expr1 + Expr2       - addition
    Expr1 - Expr2       - subtraction
    Expr1 / Expr2       - real number division  (See *MOD)
    Expr1 mod Expr2     - integer remainder     (See *INT)
    Expr1 div Expr2     - integer division      (See *MOD)

In fact, the name of any POP-11 procedure that takes numbers as
arguments and produces a single result can be used in making arithmetic
expressions for 'is'  (see HELP * MATH and REF * NUMBERS).  For
instance, if a procedure SUMSQ produced the sum of the squares of two
numbers, it would be possible to say:

    ?- X is 3 + sumsq(23,34).

If 'sumsq' was additionally declared as an operator (eg
?- op(20,xfy,sumsq). See PLOGHELP * OP) then it would be possible to
write:

    ?- X is 3 + 23 sumsq 34.

as an equivalent to the above goal.


-- USING 'IS' TO EVALUATE NON-ARITHMETIC POP-11 EXPRESSIONS -----------

'is' can be used to evaluate the Prolog representation of non-arithmetic
POP-11 expressions also. As with arithmetic expressions, care must be
taken that the POP-11 expressions return only one result.  See
PLOGHELP * ARE for a library package which allows you to evaluate POP-11
expressions which return any number of results.

Here is an example of how 'is' can be used in a non-arithmetic context:

    ?- X is rev(hd([[black, and, blue], [cats, and, dogs]])).
    X = [blue, and, black] ?
    yes

See PLOGHELP * PLOGTOPOP and PLOGHELP * MIXED_LANGUAGES for other ways
of calling POP-11 from Prolog.


-- PROLOG_EVAL --------------------------------------------------------

The predicate 'is' is equivalent to the built-in predicate
'prolog_eval/2' (see PLOGHELP * PROLOG_EVAL).


-- RELATED DOCUMENTATION ----------------------------------------------

HELP * MATH
 Overvie of mathematical operations and procedures in POP-11

PLOGHELP * ARE
 Evaluating POP-11 expressions which return any number of results

PLOGHELP * ARITHMETIC
 Overview of HELP files dealing with operations on numbers

PLOGHELP * MIXED_LANGUAGES
 Overview of methods of interfacing Prolog and other languages

PLOGHELP * PLOGTOPOP
 How to call POP-11 from Prolog

PLOGHELP * POPSTRING
 How to put POP-11 strings in Prolog programs

PLOGHELP * POPTOPLOG
 How to call Prolog from POP-11

PLOGHELP * PROLOG_EVAL
 How to evaluate the Prolog representation of a POP-11 expression

PLOGHELP * PROLOG_LANGUAGE
 Predicates and library package for switching from Prolog to POP-11

PLOGHELP * SIMPLEPOP
 Library package to do simple things in POP-11 from Prolog

REF * NUMBERS
 Detailed description of operations on numbers in POPLOG

--- C.all/plog/help/is -------------------------------------------------
--- Copyright University of Sussex 1988. All rights reserved. ----------
