Python syntax in Lisp and Scheme

Pascal Costanza costanza at web.de
Sat Oct 11 14:41:41 EDT 2003


Alex Martelli wrote:

> Jon S. Anthony wrote:
>    ...
> 
>>>>Can someone write a nifty Python hack to figure out how many times
>>>>Lispniks have tried to get Alex to explain how macros are any different
>>>>than high-order functions or new classes when it comes to The
>>>>Divergence Problem? I love that we have given it a name, by the way.
>>>
>>>The very 'feature' that was touted by Erann Gat as macros' killer
>>>advantage in the WITH-CONDITION-MAINTAINED example he posted is the
>>>crucial difference: functions (HO or not) and classes only group some
>>>existing code and data; macros can generate new code based on examining,
>>>and presumably to some level *understanding*, a LOT of very deep things
>>>about the code arguments they're given.
>>
>>Are you really this dense?  For crying out loud - functions can
>>generate code as well and just as easily as macros.  In fact macros
>>are just functions anyway so it really should go without saying.
> 
> 
> These assertions may hold in your favourite corner of the world, but
> they surely don't in mine.  So, cry out just as loud as you want, and
> keep insulting me at will, but you will hardly change my opinion: functions
> _compute and return a result_ (which may be another function, but that's a 
> detail) -- they cannot in any way break nor bend the syntax of the language 
> [in non-pure-FP languages, including Python and lisp, functions can also 
> have side effects, but that's another debate -- since c.f.programming is 
> not in the list of groups targeted by this sub-sub-thread we probably don't 
> need to pursue it].  Macros can.  Even Gat asserts that "in MOST cases" the
> divergent language one builds with macros is a superset of lisp -- which
> means it needs not be.  Without macros, you cannot alter the syntax and
> make the language in which you embed your functions a different one,
> perhaps not even a superset of the one you started with.  You can of
> course implement a _separate_ language (hey, most language implementations
> around today are probably coded in C, even for languages that have nothing 
> at all to do with C), but that's quite different from mixing language and 
> meta-language freely.

Macros are localized. When you see something like this:

(with-whatever ...
   ...)

You can be pretty sure that the effect of the macro spans only the 
extent of that macro.

This is similar to what you can do with local functions:

(flet ((print (x) ...))
   ...)

Now, in the scope of that local definition, the previously defined print 
function gets a new meaning.

Nothing breathtaking going here in both examples.


Does Python allow local function definitions? Can they shadow predefined 
functions?


Pascal





More information about the Python-list mailing list