HELP PERCENT                                       Steven Hardy Mar 1982

The percent symbol, %, has a number of different uses in POP-11. (For a
detailed tutorial introduction, see TEACH *PERCENT.)

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

 -- Use 1: Evaluating structure constants
 -- Use 2: Partial application
 -- Use 3: Dynamic local expressions


-- Use 1: Evaluating structure constants ------------------------------

The first use is in structure constants. Normally, structure constants
are unevaluated, so, for example:

     [the sum of 3 and 4 is 3 + 4] =>
     ** [the sum of 3 and 4 is 3 + 4]

Surrounding part of a structure constant with percents causes it to be
evaluated, for example:

     [the sum of 3 and 4 is %3 + 4%] =>
     ** [the sum of 3 and 4 is 7]

Any number of expressions can be surrounded by percents, but they must
then be separated with commas. So, for example, the following two
expressions are equivalent:

     [%x% %y%]
     [%x, y%]

Whereas
    [%x y%]

will produce the same syntactic error message as

    x y

If an expression surrounded by percents produces more than one result
(i.e. it leaves more than one thing on the stack), then all the results
go into the structure, for example:

     [%10 // 3%] =>
     ** [1 3]

Percents may be used in vector expressions as well as list expressions:

    {a vector with % 3 + 2 % items } =>
    ** {a vector with 5 items}

And with -cons_with-, as in the following expression to construct a
string of characters:

    vars char;
    cons_with consstring {%for char from 65 to 75 do char endfor %} =>
    ** ABCDEFGHIJK

(See HELP * ASCII for the representation of character codes).

For more examples of the use of % see TEACH * PERCENT.

If the percent symbol is used in a string expression it is taken as
part of the string:

    'a b c % d e f % g h' =>
    ** a b c % d e f % g h

See also

HELP *LISTREAD  - reads in lists without evaluating constants


-- Use 2: Partial application -----------------------------------------

The second use of percents is to provide partial application. The
expression:

     foo(%a, b%)

creates a 'closure' of -foo-, that is a new procedure in which the last
two arguments of -foo- have -a- and -b- as 'frozen' values. The same
thing is done by the following:

     partapply(foo, [%a, b%])

or

    consclosure(foo, a, b, 2)

See also

    HELP *CLOSURES  --- A summary of closures in POP-11
    HELP *PARTAPPLY --- A summary of partial application in POP-11

    REF *PROCEDURE  --- Details on procedures in POP-11


-- Use 3: Dynamic local expressions -----------------------------------

Percent symbols can be used with -dlocal- to indicate actions to be
taken on procedure entry and exit, including abnormal entry or exit such
as use of -chain-, or running or resuming processes. For further details
see HELP * DLOCAL


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