[Python-Dev] replacing 'global'

Alex Martelli aleaxit at yahoo.com
Sun Oct 26 05:20:16 EST 2003


On Sunday 26 October 2003 04:29, Guido van Rossum wrote:
> > > How about adding a "rebinding" operator, for example spelled ":=":
> > >
> > >    a := 2
> >
> > I expect Guido would object to that on the grounds that
> > it's conferring arbitrary semantics on a symbol.
>
> Hardly arbitary (I have fond memories of several languages that used :=).

Now, operator :=) MIGHT indeed be worth considering -- "rebinding
assignment with a smile"!

Yes, of course := IS a very popular way to denote assignment.


> But what is one to make of a function that uses both
>
>   a := 2
>
> and
>
>   a = 2

What would astonish me least: the presence of a normal rebiding would
ensure a is local.  I would prefer, therefore, if the compiler AT LEAST
warned about the presence of := at the same scope, and probably I'd
be even happier if the compiler flagged it as an outright error.  I just 
can't think of good use cases for wanting both at the same scope on
the same name.  I can think of a dubious one: a style where = would
be used as "initializing declaration" for a name at function start, and
all further re-bindings of the name systematically always used := -- I
can think of people who might prefer that style, but it might be best for
Python to avoid style variance by forbidding it (since it obviously can't
be _mandated_, thanks be:-).

By forbidding compresence of = and := on the same name at the same 
scope, := becomes an unmistakable yet unobtrusive symbol saying "this 
assignment here is to a NON-local name", and thus amply satisfies my
long-debated unease wrt "global".


Alex




More information about the Python-Dev mailing list