Could Emacs be rewritten in Python?

Alexander Schmolck a.schmolck at gmx.net
Thu Apr 10 09:41:54 EDT 2003


Jeff Epler <jepler at unpythonic.net> 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.


'as





More information about the Python-list mailing list