Lambda Expressions
Date: 2020-10-07 18:10:00

Up | Next | Prev | PrevTail | Tail

### 17.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:

⟨LAMBDA expression⟩ ::= |
LAMBDA ⟨varlist⟩⟨terminator⟩⟨statement⟩

where

⟨varlist⟩ ::= (⟨variable⟩,…,⟨variable⟩)

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 preﬁx 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.

Up | Next | Prev | PrevTail | Front