A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-October/039074.html below:

[Python-Dev] accumulator display syntax

[Python-Dev] accumulator display syntax [Python-Dev] accumulator display syntaxGuido van Rossum guido at python.org
Mon Oct 20 12:37:17 EDT 2003
> On Monday 20 October 2003 04:30 pm, Guido van Rossum wrote:
> > > We are indeed sure (sadly) that list comprehensions leak control variable
> > > names.
> >
> > But they shouldn't.  It can be fixed by renaming them (e.g. numeric
> > names with a leading dot).
> 
> Hmmm, sorry?
> 
> >>> [.2 for .2 in range(3)]
> SyntaxError: can't assign to literal
> 
> I think I don't understand what you mean.

I meant that the compiler should rename it.  Just like when you use a
tuple argument:

   def f(a, (b, c), d): ...

this actually defines a function of three (!) arguments whose second
argument is named '.2'.  And the body starts with something
equivalent to

   b, c = .2

For list comps, the compiler could maintain a mapping for the listcomp
control variables so that if you write

  [x for x in range(3)]

it knows to generate bytecode as if x was called '.7'; at the bytecode
level there's no requirement for names to follow the identifier syntax.

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4