Let's Talk About Lambda Functions!

James J. Besemer jb at cascade-sys.com
Wed Jul 31 06:17:26 EDT 2002


Ian Bicking wrote:

> > Decades before anyone implemented a programming language, Alonzo Church
> > boiled all the control structures down to just one: lambda.

Lambda and the Lambda Calculus have nothing to
do with "control structures," per se.  The lambda
notation itself allowed the definition of True and False,
predicates and a conditional expression, the value of
which is one of two sub expressions based on a
governing predicate.  Technically, however, there's
no 'control,' as everything was evaluated, even the
sub expression that was discarded.  There is no looping
either, only recursive applications of lambda.

Conditional expression and recursion have some
vague similarities to if/then/else and while, respectively.
But in a purely functional language like the Lambda
Calculus, it seems a gross distortion to call them
'control structures'.  When everything is an expression,
there's no "flow" to "control".

Lisp actually added "PROG" and other constructs as
alternatives to lambda in order to overcome this
limitation of pure lambda forms.

> And Smalltalk *pretends* to implement something like the lambda calculus
> -- but deep down, they had to use the same if statements we all use (for
> performance reasons).

I don't see why you say "pretends".  Smalltalk IMO
actually does an excellent job generalizing the notion
of Lambda and integrating it with arbitrary sequences
of code.

Smalltalk's "blocks" are more powerful than Python's
Lambda and even Church's Lambda notation.  Actually,
in function they resemble some of the extensions proposed
earlier in this thread, in that they may appear anywhere
an expression may be used, they associate a formal
argument list with an arbitrary statement sequence,
they optionally may be assigned to a variable and
they can be evaluated at a later time given an actual
arg list.  This language design task was simplified by
the fact that the executable portion of Smalltalk consists
of sequences of message sends (which essentially are
expressions).

Smalltalk code "block":

    [ :x :y | sequence of expressions in x and y and others ]

The block can be assigned to a name:

    egBlock := [ :x :y | sequence of expressions in x and y and others ]

and then evaluated at a later time:

    egBlock value: 3 value: 5

Smalltalk's control structures have no pretension
whatsoever to be related to lambda (or anything
else I've ever seen before).  Some examples:

    count timesRepeat: [ block of code ]

    [ count <= max ]
            whileTrue: [ another block ]

    x < 10
        ifTrue: [ true block ]
        ifFalse: [ false block ]

Furthermore, I dare say Smalltalk's choice of these
constructs were dictated by the language's universal
object/message metaphor, having little or no bearing
on performance.

Regards

--jb



--
James J. Besemer  503-280-0838 voice
http://cascade-sys.com  503-280-0375 fax
mailto:jb at cascade-sys.com






More information about the Python-list mailing list