Anonymous functions (and classes)

Hellen Claggett hellen at claggetts.net
Thu Apr 4 11:38:12 EST 2002


Hello,

Here is a relativly simple feature that I would like to use while
programming in Python. First, I did make a (brief) effort to determine
if this specific request had been made and found nothing obvious in the
PEPs or in this year's python-list archives.

I would like to be able to define anonymous functions and classes by
omitting the function or class name normally found after the def or
class keyword. For example, the following two function definitions would
be equivalent:

def comfy(color='red'): print color, "comfy chair"
comfy = def(color='red'): print color, "comfy chair"

similarly, the following two class definitions would be equivalent

class Comfy(object): pass
Comfy = class(object): pass


My two Pythonic* reasons for wanting this are:

- Greater control over your namespace allowing the programmer to define
a new function/class that is _not_ in the current namespace (Design
Principle 19 :-)

- A lambda replacement which is more consistent with all other function
definitions. (Design Principles 9 & 13)


Any comments? I'm particually curious to know how painful this change
would be to python's innards.

Thanks for your time,

Jonathan

*See: http://python.org/dev/culture.html












More information about the Python-list mailing list