Python syntax in Lisp and Scheme

Pascal Costanza costanza at web.de
Sun Oct 12 12:15:44 EDT 2003


Terry Reedy wrote:

> "Pascal Costanza" <costanza at web.de> wrote in message
> news:bm9it8$6j5$1 at newsreader2.netcologne.de...
> 
>>Does Python allow local function definitions?
> 
> 
> Module level functions are local to the module unless imported by
> another module.  Nested functions are local to the function they are
> nested within unless explicitly returned.  Methods are local to
> classes and subclasses.  Lambda expressions are very local unless
> somehow passed around.
> 
> I am not sure which best meets your intention.
> 
> 
>>Can they shadow predefined functions?
> 
> 
> Yes, named objects, including functions can (locally) shadow
> (override) builtins.  It is considered a bad habit/practice unless
> done intentionally with a functional reason.

Well, this proves that Python has a language feature that is as 
dangerous as many people seem to think macros are.

<irony>
What you say is that local function definitions can obscure the meaning 
of the Python language and/or its standard library, and this has the 
potential to split the language community and make it impossible to read 
each other's code. Heck, you really can't rely on the fact that sum(...) 
sums its arguments? This means that a local function definition is 
really a dangerous language feature, isn't it? Shouldn't it better be 
abandoned?
</irony>

That last paragraph sounds as non-sensical to your ears as the arguments 
against the inclusion of macros into a language because of their 
expressive power sound to our ears.

BTW, do you know the talk "Growing a Language" by Guy Steele? See 
http://www.research.avayalabs.com/user/wadler/steele-oopsla98.pdf - read 
it, it's very insightful (even though it talks about Java. ;)

Pascal





More information about the Python-list mailing list