a = b = 1 just syntactic sugar?

Nielson Family junk at geekabytes.net
Mon Jun 9 10:22:31 EDT 2003


Paul,

Very interesting.  Thanks for the feedback.

IMHO, the self-reference is easier to read.

-- Seth James Nielson

Paul Foley wrote:

>On Sat, 07 Jun 2003 15:49:21 -0600, junk  wrote:
>
>  
>
>>Okay,  I know this is somewhat tangential to your discussion; please
>>excuse my interruption.
>>    
>>
>
>  
>
>>If you care, I wrote a little function that will return the current
>>function within a block.  This means, you can have anonymous recursive
>>functions like this:
>>    
>>
>
>  
>
>>import selfref
>>factorial = lambda x: ((x==0)*1) or (x * selfref.myself(x-1))
>>    
>>
>
>  
>
>>Feedback please?
>>    
>>
>
>What's wrong with
>
>  factorial = lambda x: (lambda f: (lambda f: f(f)(x))(lambda g: lambda x: f(g(g))(x)))(lambda f: lambda x: (x==0)*1 or x*f(x-1))
>
>
>Or, more readably,
>
>  Y = lambda f: (lambda g: g(g))(lambda g: lambda h: f(g(g))(h))
>
>  factorial = Y(lambda f: lambda x: (x==0)*1 or x*f(x-1))
>
>or
>
>  factorial = Y(lambda f: lambda x: x<2 and 1 or x*f(x-1))
>
>
>  
>







More information about the Python-list mailing list