Mailing List Archive

Why no "def A.f (...)"?
Are there sensible reasons (performance, anomalies..) why
function definition is restricted to creating new identifiers
in the current namespace?

An extended syntax

def A.B.f (self, x):
<body>

with semantics like

setattr (A.B, "f", lambda self, x: <body>)

would be the most straight forward solution for my current problem,
creating classes at runtime. -- OK, of course there are *lots* of
other ways to do this, but it would also make the language a
little bit more homogenous IMHO.

Does anyone else see a use for this?

Stefan
Why no "def A.f (...)"? [ In reply to ]
Stefan> Are there sensible reasons (performance, anomalies..) why
Stefan> function definition is restricted to creating new identifiers in
Stefan> the current namespace?

The only obvious reasons I can see are

a. it's perhaps poor taste to add functions to another module (granted,
no worse taste than adding any other kind of object to another module)
b. it's easily done with a def following by an assignment statement
c. it hasn't been considered important enough to warrant modifying the
grammar

Skip Montanaro | http://www.mojam.com/
skip@mojam.com | http://www.musi-cal.com/~skip/
847-971-7098