[Python-Dev] replacing 'global'
aleaxit at yahoo.com
Mon Oct 27 13:40:31 EST 2003
On Monday 27 October 2003 07:00 pm, Just van Rossum wrote:
> Guido van Rossum wrote:
> > The only problem with using :: is a syntactic ambiguity:
> > a[x::y]
> > already means something (an extended slice with start=x, no stop, and
> > step=y).
> On the other hand:
> a[x y]
> doesn't mean anything, so I don't see an immediate problem.
Sorry, just, but I really don't understand the "don't see immediate problem".
As I understand the proposal:
y = 23
biglist = range(999)
y = 45 # sets a local
::y = 67 # sets the global
should this print the 67-th item of biglist, or the first 45 ones?
a[x::y] is similarly made ambiguous (slice from x step y, or index at
y in scope x?), at least for human readers if not for the compiler --
to have the same expression mean either thing depending on whether
x names an outer function, a local variable, or neither, or both, for
example, would seem very confusing to me.
> I like Neal's proposal, including the "::" digraph.
I just don't see how :: can be used nonconfusingly due to the
'clash' with "slicing with explicit step and without explicit stop" (ambiguity
with slices with implicit 0 start for prefix use, a la ::y -- ambiguity with
slices with explicit start for infix use, a la x::y).
A digraph, single character, or other operator that could be used
(and look nice) in lieu of :: either prefix or infix -- aka "stropping by
any other name", even though the syntax sugar may look different
from Ruby's use of prefix $ to strop globals -- would be fine. But
I don't think :: can be it.
More information about the Python-Dev