HELP PROCEDURE                         A. Sloman and S. Hardy, Aug 1982

    vars procedure foo;

    procedure(<formal parameters>) -> <output parameters>;
        <body>
    endprocedure;

The syntax word PROCEDURE has two uses.

(1) It can be used to declare an identifier as of type PROCEDURE, e.g.

    vars procedure foo;
    constant procedure foo;
    vars procedure(foo1, foo2, foo3);

to declare FOO to be a procedure identifier. It can also be used in the
heading of a procedure definition, e.g.

define foo(<list>, procedure <identifier1>) -> procedure <identifier2>;

specifies that FOO takes two arguments, of which the second must be a
procedure, and produces one result, also a procedure.

See also HELP *VARS and *CONSTANT.

(2) The word PROCEDURE  can be used to introduce an anonymous procedure;
i.e. it tells the compiler to build a procedure, much as "[" tells it to
build a list. The procedure is not named, unlike procedures created
using DEFINE. The format is

    procedure(<formal parameters>) -> <output parameters>;
        <body>
    endprocedure;

There need not be any formal parameters. If there are no output
parameters, the "->" is omitted. (There are optional additional
specifiers WITH_PROPS and WITH_NARGS which can be used in a procedure
header. For details see REF SYNTAX and HELP *WITH_NARGS.)

The procedure built is left on the stack, thus:

    procedure(x); x + 1 endprocedure +>
    ** <procedure>

Usually we will want to do something with the procedure, for example:

    procedure(x); x + 1 endprocedure(3) =>
    ** 4

    maplist([10 3 7], procedure(x); x + 1 endprocedure) =>
    ** [11 4 8]

Frequently we want to assign a procedure to a variable, thus:

    vars addone;
    procedure(x); x + 1 endprocedure -> addone;

    addone(3) =>
    ** 4

POP11 provides some 'syntactic sugar' for a combined declaration of
a variable and assignment to the variable:-

    define addone(x); x + 1 enddefine;

is a neater way of saying that you want the variable ADDONE declared and
to have a procedure as its value. i.e. it declares a variable and
assigns as its value a procedure.  (N.B. DEFINE also stores the name of
the new procedure in its *PDPROPS, which is useful for debugging).
PROCEDURE notation is most frequently used when passing procedures as
arguments; for examples of this use of the PROCEDURE notation see HELP
*MAPLIST.

For compatibility with older POP2 systems "LAMBDA" is defined as a macro
which is synonymous with "PROCEDURE". In addition "END" can be used
instead of "ENDPROCEDURE" (see HELP *DEFINE).

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

See also
TEACH *DEFINE   - tutorial introduction to defining procedures
HELP *DEFINE    - for form and content of procedure definitions
HELP *MAPLIST   - applying a procedure to each element of a list
HELP *PDPROPS   - variable storing information about a POP-11 procedure
REF  *PROCEDURE - details of the nature of procedures in POP-11

--- C.all/help/procedure -----------------------------------------------
--- Copyright University of Sussex 1987. All rights reserved. ----------
