[Pyrex] fan mail; ideas for the future?

Michal Wallace michal at sabren.com
Tue Oct 11 17:41:48 CEST 2005


On Tue, 11 Oct 2005, Greg Ewing wrote:

> William Stein wrote:
> 
> > It would also be nice to support list comprehensions in Pyrex.  How
> > difficult would this be to add?
> 
> It shouldn't present any particular difficulty, since
> it's just syntactic sugar for a for-loop. The details
> could be a bit tedious, though, and so far I haven't
> felt it to be worth the effort. I'll keep the idea in
> mind for the future.


We implemented list comprehensions for pirate using 
a tree transformation on the nodes from the compiler 
module. I'm not sure how similar your AST is to the
compiler AST, but this might help someone interested
in porting it:

   http://pirate.versionhost.com/viewcvs.cgi/pirate/simple.py


Basically we wrap the expression part in a
new ListCompCore node, and then turn the 
children into a tree..

When it comes time to render the code, we
turn ListCompCore into a "tmp.append(expr)" statement
and prefix the original listComp node with
"tmp = []", followed by the for loop we created
in the transformation. (where tmp is really an 
artibrary unique symbol of course)


Sincerely,
 
Michal J Wallace
Sabren Enterprises, Inc.
-------------------------------------
contact: michal at sabren.com
hosting: http://www.cornerhost.com/
my site: http://www.withoutane.com/
-------------------------------------




More information about the Pyrex mailing list