REDUCE

21.4 Lambda Expressions

lambda expressions provide the means for constructing Lisp lambda expressions in symbolic mode. They may not be used in algebraic mode.

Syntax:

\(\langle \)lambda expression\(\rangle \) \(\longrightarrow \) lambda \(\langle \)varlist\(\rangle \)\(\langle \)terminator\(\rangle \) \(\langle \)statement\(\rangle \)

where

\(\langle \)varlist\(\rangle \) \(\longrightarrow \) (\(\langle \)variable\(\rangle \),,\(\langle \)variable\(\rangle \))

e.g.,

        lambda (x,y); car x . cdr y;

is equivalent to the Lisp lambda expression

        (lambda (x y) (cons (car x) (cdr y)))

The parentheses may be omitted in specifying the variable list if desired.

lambda expressions may be used in symbolic mode in place of prefix operators, or as an argument of the reserved word function.

In those cases where a lambda expression is used to introduce local variables to avoid recomputation, a where statement can also be used. For example, the expression

    (lambda (x,y); list(car x,cdr x,car y,cdr y))
        (reverse u,reverse v)

can also be written

    {car x,cdr x,car y,cdr y}
        where x=reverse u,y=reverse v

Where possible, where syntax is preferred to lambda syntax, since it is more natural.


Hosted by Download REDUCE Powered by MathJax