Let's Talk About Lambda Functions!

Ian Bicking ianb at colorstudy.com
Tue Jul 30 14:46:16 EDT 2002


On Tue, 2002-07-30 at 11:05, John Roth wrote:
> I tend to agree with you on that one, but it's a matter of style. I
> observe
> that e.g. Smalltalk style does anonymous code blocks all over the place.

I've seen people argue that you can do all the same things with
iterators as Smalltalk does with code blocks.  And, really, it's not as
though Smalltalk has truly novel control structures -- everything still
boils down to while, for, and if.  Smalltalk does give you easy
callbacks, though.

> There's no reason my proposal couldn't be extended to anonamous
> classes: the syntactic issues are exactly the same. The difficulty is
> in extending it to methods, as opposed to functions. The only way
> to distinguish a method from a function today is to observe that
> methods are defined at the top level of a class; a def anywhere
> else is a function (I think.)

A method is just a function that is bound to a class variable.  So you
can do something like:

class X:
    pass

X.func = lambda self, x: x * 2
x = X()
x.func(10)
==> 20

In fact, you can even do:

class X:
    func = lambda self, x: x * 2


  Ian






More information about the Python-list mailing list