Could Emacs be rewritten in Python?
Skip Montanaro
skip at pobox.com
Tue Apr 8 11:04:48 EDT 2003
>>>>> "Kim" == Kim Petersen <kp at kyborg.dk> writes:
>> (defun foo()
>> (message "when foo is called folding is: %s" case-fold-search))
>> (defun bar()
>> (message "when bar is called folding is: %s" case-fold-search)
>> (let ((case-fold-search t))
>> (foo))
>> (message "now folding is: %s again" case-fold-search))
>> (bar)
Kim> hmmm - occured to me that you might mean that case-fold-search was
Kim> a global variable first - then local.... but that wouldn't matter
Kim> to this since we would need to do lookup in locals first _then_ in
Kim> globals (as expected)
Look again. In Elisp, when foo() looks up the value of case-fold-search it
will find the value defined in the let statement inside bar() because it's
lexically scoped (looks up the call chain for values). If this was Python,
the reference to case-fold-search in foo() would be resolved at the global
scope because Python is statically scoped (looks in locals, globals, then
builtins only - ignoring nested functions which this case doesn't involve).
If the global value of case-fold-search was nil (False), elisp would would
print
when bar is called folding is: nil
when foo is called folding is: t
now folding is: nil
The textually equivalent Python would print
when bar is called folding is: False
when foo is called folding is: False
now folding is: False
Skip
More information about the Python-list
mailing list