Could Emacs be rewritten in Python?

Carl Banks imbosol-1050127854 at aerojockey.com
Sat Apr 12 02:40:42 EDT 2003


Christian Tanzer wrote:
> Dynmaic scoping is used for lots of things in Emacs. With a different
> design many of those uses could certainly be replaced by a simpler
> design. I doubt that one could easily replace all of them, though.
> 
> As someone else pointed out, dynamic scoping is used to change values
> of functions called indirectly -- thus converting them into arguments
> passed around doesn't really work.

No, but lexical closures can do this just fine:

    def a():
        value_to_be_passed_indirectly = some_calculation()
        def b():
            do_something_with(value_to_be_passed_indirecty)
        call_function_that_calls_callback(b)


Not to mention you can do similar stuff with a class:

    def a(self):
        closure = B(some_calculation())
        call_function_that_calls_callback(closure.b)
 
    class B:
        def __init__(self,value):
            self.value_to_be_passed_indirectly = value
        def b(self):
            do_something_with(self.value_to_be_passed_indirecty)


The fact is, arguments have been passed indirectly in Python for a
long time, happily, and without dynamic scoping.  It will not be hard
to replace this use of dynamic scoping.


> One could use a
> temporary-global-binding approach (or better temporary-object-binding
> [as in temporarily overriding a buffer attribute]), but without special
> forms like `with-` style macros it would look rather clumsily.

Even if you did want to do this, it would hardly be clumsy to use a
try ... finally.


-- 
CARL BANKS




More information about the Python-list mailing list