Anonymus functions revisited

Ron radam2 at tampabay.rr.com
Tue Mar 22 22:32:08 EST 2005


On Tue, 22 Mar 2005 21:45:42 +0100, Bruno Desthuilliers
<bdesth.quelquechose at free.quelquepart.fr> wrote:

>Ron a écrit :
>> On 21 Mar 2005 22:37:42 -0800, "Kay Schluehr" <kay.schluehr at gmx.net>
>> wrote:
>> 
>> 
>>>Mappings like that:
>>>
>>>  ((x,y),z)   -> x+y-z
>>>
>>>  ((x,y=0),z) -> None
>>>
>>>should be valid actions too.
>>>
>>>What is the audience thinking about that?
>> 
>> 
>> I think that there's too much implied,  and that in the long run it,
>> if we keep addding in special shortcuts, it will lead to very dificult
>> to read code.  
>> 
>Don't like Perl ?-)

I tried it..  Wrote a html reformatter in it a long time ago. Wasn't
tempted to do anything else with it. It was good for that, but I went
a month later and had trouble figuring out how it worked. :)

>The problem here is that Kay's proposition mixes two points: flexible 
>tuple unpacking and a new syntax for anonymous functions.

Yes, two different problems. I don't think anything needs to be done
to tuples myself.  I tend to use lists more anyway.


As far as anonymous functions go...  What if there where a container
type to hold unexecuted python code until it is asked to do it. And to
be able to assign it a name, so it would have an object class and
type. But be defined by like a tuple. No addition syntax to make
things confusing.

>>sum = (* a = b+c *)    

The (* and *) could be something more appropriate. As long as it's
easy to identify and can't be confused with anything else.


There would be an order of precedence to it also so you could do:

>>my_button_action = (*a+=c (*if b:c=1 (*if not z: b=False*) *) *)

It would execute from the inside (*_*) outward and use the local name
space it's executed in, so no passing arguments or return values.

Nesting and order of precedence has worked for a long time. to
evaluate it you would need a keyword...  

>>newlamba  my_button_action
 

or this could be valid:
>>newlamba (* a+=c (* if b:c=1 (* if not z:b=False *) *) *)

or left to right order of execution:
>>newlamba (* a = b+c+d, if a>limit:done=True *)

If argument passing is really needed, I suppose there could be an
export/inport method attached to it.

>>newlamba (* sum = a+b *).import(a,b).export(sum)

or
>>newlamba (* sum = a+b *).in_out(a,b -> sum)

>>newlamba my_button_action.in_out(a,b ->sum)


A differnt name would be nice...  code, docode, dothis, process... ?

or if you require the in_out method to start it, you don't need the
keyword.


>> mybutton = (* sum = a+b *)        # does not execute, but binds it to a

>> b = mybutton.in_out(a,b -> sum)   # This evaluates first, the sum is bound to b.

>> b = (* sum = a+b *).in_out(a,b -> sum)   # Is the same as above.


Yes,  there are probably loads of stuff wrong with this.  ;-)

Ron Adam

(Looks like another Ron joined the group.)





More information about the Python-list mailing list