Suggestions for python 2

Tim Peters tim_one at email.msn.com
Wed Jan 19 00:29:03 EST 2000


[Evan Simpson]
> Now that two people have asserted that lexical scoping is
> the right way to handle this, I'd like to know what they
> *mean* by lexical scoping.

People with Scheme backgrounds mean "what Scheme does"; people with Pascal
backgrounds, "what Pascal does"; people with Perl backgrounds know they need
it but aren't really sure what anything means <wink>.

> How would names get bound to (or just initialized from?)
> names in lexically enclosing scopes?  Implicitly? Explicitly?
> Would we still declare module-global variables, or would
> they use the same mechanism as names in intermediate scopes?

It's a bit of a puzzle in a language without declarations; I'm not sure any
language has tried to "do" lexical closures without them (Scheme has "let" &
friends, Perl "my", & so on -- they're not declaring *types*, just declaring
which scope a *name* belongs to).

Channeling Guido <wink>, the rules for what's local wouldn't change.  A
reference to a non-local name would resolve to the closest-containing scope
in which the name *was* local (and, since the global and local namespaces
are the same at module level, this is a generalization of what happens
today).  Although I believe John Skaller warped "global" to mean "non-local"
in Viper, Guido wouldn't do that:  "global" would continue to mean "module
level".  Guido would not allow rebinding of a non-local name (except in that
a name explicitly declared global could, just as today, be rebound); "if
it's bound, it's local" would remain the rule.

That's one version of the truth; Viper has another; many other variants were
debated in the dim past.  The version above is The Truth because that's what
Guido actually implemented several years ago, before bumping into a nasty
cyclic trash problem (subsequently wormed around by Greg Ewing in his
lexical closure patch, very cleverly but incompletely and "too cleverly"
<0.9 wink>).

> I rather like the idea of having to explicitly bring names
> into an inner scope,

Me too -- except in the cases that bite most often, where a trivial little
lambda wants to refer to one or two measly little names from its context.
People stumble on that so often it's a FAQ.

> and with semantics identical to parameter defaults.

Sorry, this part's unclear.

> Why is this so objectionable?  Is it just the syntax?

I've getting over a bad flu, and not thinking entirely clearly yet, but when
I read Markus Stenberg's

> Ugh.. *puke* this looks like ugly hack from hell

I kinda figured, ya, maybe there is some small objection to the syntax out
there <wink>.

when-guido-sez-"too-radical"-he-means-"not-radical-
    enough"-ly y'rs  - tim






More information about the Python-list mailing list