problem with variable scoping

Tim Peters tim_one at email.msn.com
Sun May 30 00:49:09 EDT 1999


[Moshe Zadka]
> Well, as I understand (and at least want) static scoping, it implies the
> full power of closures -- i.e., more then the ``two name spaces'' paradigm
> of Python. I think the problem Python doesn't have a true Scheme-ish
> define, and '=' (i.e., Python's set!) implies define in strange ways
> (i.e., the one I did not expect: set! anywhere in the body implies a
> define, unless there is the global keyword. Did I get that right?)

Explaining Python in terms of Scheme semantics is like explaining Japanese
culture in terms of, oh, Rwandan culture.  Python does what it does; indeed,
almost all languages do, and even some Schemes treat "define" and "set!" as
synonyms <wink>.

Static scoping still makes sense in the absence of indefinite extent (what
you really mean by "closure"), and that's what most languages outside the
Lisp world adopt (from C to Java).  Arbitrary namespace nesting + indefinite
extent may be in Python2; a technical hangup with garbage collection
prevents it in Python1, unless you simulate it by hand via default-argument
abuse (search DejaNews if you're intrigued).

> still-waiting-for-arbitary-expressions-in-lambdas-

Already there:  they're called "def".  Honest!  lambda is nothing but
syntactic sugar for a particularly simple form of def in Python, and adds no
power to the language.  All in all, lambda shouldn't have been added; it's
not what people expect it to be, so just provokes endlessly useless
arguments (useless because it's too late to change).

> and-tail-call-optimization-which-is-possible-in-python-ly y'rs, Z.

It's not possible to identify a tail call at compile time (no name->object
binding is known at compile-time, and e.g. the "f(n-1)" appearing inside a
"def f:" may indeed not refer to the function f, or even to a function at
all, at runtime).

The PVM could identify tail calls dynamically, although it's not of much use
given the interpreter's current global structure.  That may change too, but
for other reasons.

Bottom line:  Anyone who intends to stick with Python is well-advised to
learn how to write a loop <wink>.

the-best-language-to-code-scheme-in-remains-scheme-ly y'rs  - tim






More information about the Python-list mailing list