[Python-ideas] Generator syntax hooks?

Steven D'Aprano steve at pearwood.info
Thu Aug 10 12:11:42 EDT 2017


On Thu, Aug 10, 2017 at 12:39:34PM -0300, Soni L. wrote:

> I'm pretty sure I read somewhere that lambdas and generators share their 
> syntax, and that syntax is already a subset of python syntax. Would it 
> be too hard to expose that with a "simplified AST" API?

I don't understand what you mean by this.

The syntax for lambda is (roughly):

     lambda parameter-list : expression

The syntax for generators is (again, roughly):

     def name ( parameter-list ) :
         suite-containing-yield


Obviously the generator suite can contain expressions, and both have a 
parameter-list. What shared syntax are you referring to, and how is it 
relevant?

Or are you referring to generator expressions, rather than generators?

     ( expression for target in expression ... )

Obviously a Python expression is a Python expression, wherever it is, so 
a lambda can contain generator expressions, and generator expressions 
can contain lambdas... 

And what do you mean by "simplified AST" API? I'm afraid your comment is 
too abstract for me to understand.



-- 
Steve


More information about the Python-ideas mailing list