[Python-Dev] parsers and compilers for 2.0

Thomas Wouters thomas@xs4all.net
Sun, 13 Aug 2000 00:34:43 +0200


On Sat, Aug 12, 2000 at 06:31:32PM -0400, Eric S. Raymond wrote:
> Neil Schemenauer <nascheme@enme.ucalgary.ca>:
> > I'm trying to keep Jeremy's compiler up to date.  Modifying the
> > parser module to understand list comprehensions seems to be none
> > trivial however. 

> Last I checked, list comprehensions hadn't been accepted.  I think
> there's at least one more debate waiting there...

Check again, they're already checked in. The implementation may change
later, but the syntax has been decided (by Guido):

[(x, y) for y in something for x in somewhere if y in x]

The parentheses around the leftmost expression are mandatory. It's currently
implemented something like this:

L = []
__x__ = [].append
for y in something:
	for x in somewhere:
		if y in x:
			__x__((x, y))
del __x__

(where 'x' is a number, chosen to *probably* not conflict with any other
local vrbls or other (nested) list comprehensions, and the result of the
expression is L, which isn't actually stored anywhere during evaluation.)

See the patches list archive and the SF patch info about the patch (#100654)
for more information on how and why.

-- 
Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!