HELP JUMPOUT                                         Steven Hardy, August 1982

JUMPOUT is used when it is convenient to exit from several procedure calls in
one step.  It's use is complicated.  A call of JUMPOUT takes two arguments: a
procedure and an integer; it returns a procedure which when applied causes the
procedure which called JUMPOUT to be exited; before this happens the procedure
given to JUMPOUT is applied.  The given integer specifies how many results
this procedure has; these are the made the results of the procedure which
originally called JUMPOUT.  One possible use of JUMPOUT is in writing
procedures to search recursive data structures. The following procedure scans
a binary tree looking for the first element which is bigger than some given
number:

    define search(num, tree);
        vars found;
        jumpout(identfn, 1) -> found;
        define scan(tree);
            if atom(tree) then
                if isnumber(tree) and tree > num then found(tree) endif
            else
                scan(hd(tree));
                scan(tl(tree))
            endif
        enddefine;
        scan(tree);
        return(undef);
    enddefine;
    search(5, [[1 4 [6 3]] 8]) =>
    ** 6
    search(9, [[1 4 [6 3]] 8]) =>
    ** undef

In this example, the procedure calling JUMPOUT is SEARCH and the procedure
returned by JUMPOUT is assigned to the variable FOUND.  When FOUND is applied
then procedure SEARCH is exitted as are any active calls of SCAN.  The
procedure given to JUMPOUT is IDENTFN which is a do-nothing procedure which
returns its argument as its single result (hence the 1 given to JUMPOUT).

It would be a mistake to try and apply FOUND after SEARCH had exitted
normally (were it do so).
