[Python-Dev] unnamed defs (original) (raw)

marcus marcus.cf at bol.com.br
Thu Jul 29 04:04:54 CEST 2004


Being unsatisfied with the way lambda works, i wondered what would the python guys think of this:

class X: ____my_static_method = staticmethod(def (x, y): { ________some statements ____})

I hope decorators will be better for this case, but it's only an example. The word 'lambda' could be used instead of 'def', i don't know what would be better.

The motivation of this suggestion is to improve consistency of the language and correcting the one-expression-lambda we currently have. Look how consistent Lua is in this regard. Passing functions to functions is considered useful by many people (essential, sometimes), but 'lambda' cannot be used even when all we need is a function that has an 'if' or an assignment, for example. 'lambda' seems to be a hack.

Since unnamed functions can to be used anywhere, i chose braces as delimiters, but indentation would work normally inside them. Also, the syntax is easy to recognize and is not ambiguous.

If Python (3.0? 2.5?) had this feature, i would be very happy!

I suspect that this subject has already been discussed, but it's easier to find lambda tricks than a good rationale of its limitations.



More information about the Python-Dev mailing list