Could Emacs be rewritten in Python?

Carl Banks imbosol-1049990205 at
Thu Apr 10 19:27:33 CEST 2003

Alexander Schmolck wrote:
> Jeff Epler <jepler at> writes:
>> Ignoring the fact that "globals" are module-level, you can obtain
>> "stacking" of global variables with only a single level of name lookup,
>> including automatic removal on return, in Python.  All that you need is a
>> convenent way to write complex things in the 'body' argument.  Untested
>> code, of course
>> _let_undef = object()
>> def let(body, **kw):
>>       restore = {}
>>       g = globals()
>>       for k, v in kw.items():
>>               restore[k] = g.get(k, _let_undef)
>>               g[k] = v
>>       try:
>>               return body()
>>       finally:
>>               for k, v in restore.items():
>>                       if v is _let_undef:
>>                               del g[k]
>>                       else:
>>                               g[k] = v
> Sure, but this is a but a clumsy, almost unusable imitation of
> scheme's (non-standard, but common) fluid-let macro. So what are you
> doing for multithreaded code (which scheme's faked dynamic extent
> via fluid-let doesn't cover easily but CL's special variables do)?
> Maybe I'm missing something, but non-dynamically scoped globals just
> seem like a bad idea to me.

What you're missing is that Globals are Evil(tm), and furthermore,
that if your program depends on changing a global in a dynamic scope,
it badly needs to be redesigned.  (To wit, that functions that refer
to the global you want to change need to be changed to accept it as an

I think dynamic scpoing is a wholly bad idea, and simplifying a very
misguided programming practice doesn't make it any less so.


More information about the Python-list mailing list