Could Emacs be rewritten in Python?

Beni Cherniavsky cben at techunix.technion.ac.il
Wed Apr 9 13:53:10 EDT 2003


Kim Petersen wrote on 2003-04-09:

> No misunderstanding... and possibly not efficient - thats why i said
> that you could do push/pop of bindings instead... since then i
> remembered that elisp (or any other lisp for that matter *doesn't* have
> global variables - so it would be inefficient). But to make it efficient
> and usable you can do it with a class instead (that simulates a dictionary):
>
> [snip]

True.  Perhaps doing it indeed with classes (without simulating
anything :-) would be even better:

class Global:
    """This is the top namespace in this example"""
    case_fold_search = 'nil'

def foo(env):
    print "When foo is called folding is:", env.case_fold_search
    env.case_fold_search = 'evil'

def bar(env):
    print "When bar is called folding is:", env.case_fold_search
    class local(env):
        case_fold_search = 't'
    foo(local)
    print "What did foo to folding?", local.case_fold_search
    print "bar's last folding is:", env.case_fold_search

def quux(env):
    print "before bar:", env.case_fold_search
    bar(env)
    print "after bar:", env.case_fold_search

quux(Global)

>>> ## working on region in file /usr/tmp/python-10913_eN...
before bar: nil
When bar is called folding is: nil
When foo is called folding is: t
What did foo to folding? evil
bar's last folding is: nil
after bar: nil

Of course, one can use instances instead of classes, I'm not sure this
is needed.

-- 
Beni Cherniavsky <cben at tx.technion.ac.il>





More information about the Python-list mailing list