Let's Talk About Lambda Functions!

John Roth johnroth at ameritech.net
Tue Jul 30 12:05:43 EDT 2002


"Jonathan Hogg" <jonathan at onegoodidea.com> wrote in message
news:B96C4374.ECA5%jonathan at onegoodidea.com...
> On 30/7/2002 12:29, in article ukcu02su9a7r5b at news.supernews.com,
"John
> Roth" <johnroth at ameritech.net> wrote:
>
> > Why bother with the restrictions? Fredrik had the right idea when
> > he said that we needed something to make it obvious that functions
> > are first class objects. That is, allow anonamous functions anywhere
> > you can have a function object.
>
> How far does one go? Classes are first-class objects, should we also
have
> anonymous classes?
>
> >>> foo = (class:
> ...            def __init__( self, x y ):
> ...                self.x = x
> ...                self.y = y
> ...       )( 5, 6 )
> >>>
> >>> foo.x
> 5
> >>>
>
> I'm a fan of lambda, but when a function is complex enough that it
can't be
> done in an in-(one-)line lambda then it should be pulled out and given
a
> name.

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.

As far as anonamous classes, again, it's a matter of style. I wouldn't
do that
simply because I think it complicates the code too much. On the other
hand, people who regularly program in languages that let that happen
might have examples where it makes sense.

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.)

John Roth
>
> Jonathan
>





More information about the Python-list mailing list