Let's Talk About Lambda Functions!

Bengt Richter bokr at oz.net
Thu Aug 1 15:46:06 EDT 2002


On Tue, 30 Jul 2002 13:21:56 +0100, Jonathan Hogg <jonathan at onegoodidea.com> wrote:

>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?
>
If it falls out from actual simplification/regularization/orthogonalization
of language expressions, IMO yes. That doesn't mean its use should be mandated.

>>>> foo = (class:
>...            def __init__( self, x y ):
>...                self.x = x
>...                self.y = y
>...       )( 5, 6 )
>>>>
>>>> foo.x
>5
>>>>
You faked that pretty well ;-) You used parens basically as I have been
suggesting (or vice versa, since I'm going through the thread now), except
that I would note that you can establish the reference indentation freely
if you move the 'class' (or 'def', as the case may be) to the next line:
 >>>> foo = (
 >...     class:
 >...         def __init__( self, x y ):
 >...             self.x = x
 >...             self.y = y
 >... )( 5, 6 ) # ')' at any col <= col of 'c' in 'class' signals final dedent

>
>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 would agree, but on I think that should be a style/convention decision.

Regards,
Bengt Richter



More information about the Python-list mailing list