Two minor syntactic proposals

Bengt Richter bokr at accessone.com
Wed Jun 20 14:30:25 EDT 2001


On Wed, 20 Jun 2001 15:31:32 +1200, Greg Ewing <see at my.signature>
wrote:
[...]
>By the way, here's another possible use -- creating 
>a dict-of-funcs for simulating a case-statement:
>
>table = {}
>
>def table['spam']():
>  ...
>
>def table['eggs']():
>  ...
[...]

This is possible now:

table={}
table['x2']=lambda x: x*2

but how about this:

# using a proposed full def version of lambda:
table['spam']=def(optional,arg,list):
    """I am (possibly) the value of 'spam' in dict table."""
    print "I was defined with full function def capabilities."
    print "I.e., multiple statements, etc."

with the effect of

define anon_spam():
    """I am (possibly) the value of 'spam' in dict table."""
    print "I was defined with full function def capabilities."
    print "I.e., multiple statements, etc."
table['spam']=anon_spam
del anon_spam

The left hand side of a table is actually irrelevant to the
main idea of the enhanced lambda capability. I.e., I wouldn't
mind in general using

foo=def(bar,baz):
    etc

instead of

def foo(bar,baz):
    etc




More information about the Python-list mailing list