[Python-Dev] replacing 'global'

Alex Martelli aleaxit at yahoo.com
Sun Oct 26 06:32:41 EST 2003

On Sunday 26 October 2003 10:13, Greg Ewing wrote:
> > Hardly arbitary (I have fond memories of several languages that used
> > :=).
> But all the ones I know of use it for ordinary assignment.
> We'd be having two kinds of assignment, and there's no
> prior art to suggest to suggest which should be = and
> which :=. That's the "arbitrary" part.
> The only language I can remember seeing which had two
> kinds of assignment was Simula, which had := for value
> assignment and :- for reference assignment (or was it
> the other way around? :-) I always thought that was
> kind of weird.

VB6 had LET x = y for value assignment and SET x = y
for reference assignment.  Yes, very confusing particularly
because the LET keyword could be dropped.  Fortunately
we're not proposing anything like that;-).

Icon had := for irreversible and <- for reversible assignment.
(also :=: and <-> for exchanges and diffferent comparisons
for == and === so maybe it HAD gone a bit overboard:-).

I do recall an obscure language where <op>= was always
augmented assignment equivalent to a = a <op> b.  But in
particular the : operator meant to evaluate two exprs and
take the RH one, like comma in C, so a := b did turn out to
mean the same as a = b BUT fail if a couldn't first be
evaluated, which (sort of randomly) is sort of close to Just's
proposal.  Unfortunately I don't remember the language's

Googling a bit does show other languages distinguishing
global from local variable assignments.  E.g, in MUF,
http://www.muq.org/~cynbe/muq/muf1_24.html ,
--> (arrow with TWO hyphens) assigns globally,
-> (arrow with ONE hyphen) assigns locally.

It appears that this approach is slightly less popular than
the 'qualification' one I suggested (e.g. in Javascript you
can assign window.x to assign the global x; in Beanshell,
super.x to assign to x from enclosing scope) which in
turn is less popular than declarations.  Another not very
popular idea is distinguishing locals and globals by name
rules, as in Ruby $glob vs loc or KVirc Glob (upper initial)
vs loc (lower initial).


More information about the Python-Dev mailing list