Let's Talk About Lambda Functions!
Ian Bicking
ianb at colorstudy.com
Wed Jul 31 12:35:57 EDT 2002
On Wed, 2002-07-31 at 05:17, James J. Besemer wrote:
> 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 ]
Well, it looks a lot like lambda calculus, because True and False are
two different classes, with definitions like:
----
(True)
ifTrue: block
block value "This evaluates the passed block"
ifFalse: block
"do nothing"
(False)
ifTrue: block
"do nothing"
ifFalse: block
block value
----
This should remind one of true/false in lambda calculus (though
obviously with a very different notation).
But, at least in Squeak (and my impression is this is universal among
Smalltalk environments), ifTrue:/ifFalse: don't actually get passed as
method calls/messages. The compiler specifically looks for those
methods, and turns them into traditional if statements in the bytecode.
That is, you can't (usefully) implement ifTrue: in your own custom
class.
Ian
More information about the Python-list
mailing list