<div dir="ltr">Heh, thanks. :-)</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 21, 2015 at 2:17 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Dang it. :-) I just want  to encourage you to continue pursuing this idea, one way or another.<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 21, 2015 at 7:01 AM, Ben Hoyt <span dir="ltr"><<a href="mailto:benhoyt@gmail.com" target="_blank">benhoyt@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks. Good point about python-ideas -- I was thinking that after I sent it too. I'll repost there soon.<div><br></div><div>Out of interest, what specifically were you referring to as "definitely cool" here: LINQ-style generator expressions that build SQL ala PonyORM, or the more general feature of enabling AST access?</div><span><font color="#888888"><div><br></div><div>-Ben</div></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 20, 2015 at 10:31 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey Ben, this is probably a better topic for python-ideas. I'll warn you that a hurdle for ideas like this is that ideally you don't want to support this just for CPython. It's definitely cool though! (Using movie poster style quotes you can turn this into a ringing endorsement: "definitely cool" -- The BDFL. :-)<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Wed, May 20, 2015 at 7:26 PM, Ben Hoyt <span dir="ltr"><<a href="mailto:benhoyt@gmail.com" target="_blank">benhoyt@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>Hi Python devs,<br>
<br>
Enabling access to the AST for compiled code would make some cool<br>
things possible (C# LINQ-style ORMs, for example), and not knowing too<br>
much about this part of Python internals, I'm wondering how possible<br>
and practical this would be.<br>
<br>
Context: PonyORM (<a href="http://ponyorm.com/" target="_blank">http://ponyorm.com/</a>) allows you to write regular<br>
Python generator expressions like this:<br>
<br>
    select(c for c in Customer if sum(c.orders.price) > 1000)<br>
<br>
which compile into and run SQL like this:<br>
<br>
    SELECT "c"."id"<br>
    FROM "Customer" "c"<br>
    LEFT JOIN "Order" "order-1" ON "c"."id" = "order-1"."customer"<br>
    GROUP BY "c"."id"<br>
    HAVING coalesce(SUM("order-1"."total_price"), 0) > 1000<br>
<br>
I think the Pythonic syntax here is beautiful. But the tricks PonyORM<br>
has to go to get it are ... not quite so beautiful. Because the AST is<br>
not available, PonyORM decompiles Python bytecode into an AST first,<br>
and then converts that to SQL. (More details on all that from author's<br>
EuroPython talk at <a href="http://pyvideo.org/video/2968" target="_blank">http://pyvideo.org/video/2968</a>)<br>
<br>
I believe PonyORM needs the AST just for generator expressions and<br>
lambda functions, but obviously if this kind of AST access feature<br>
were in Python it'd probably be more general.<br>
<br>
I believe C#'s LINQ provides something similar, where if you're<br>
developing a LINQ converter library (say LINQ to SQL), you essentially<br>
get the AST of the code ("expression tree") and the library can do<br>
what it wants with that.<br>
<br>
What would it take to enable this kind of AST access in Python? Is it<br>
possible? Is it a good idea?<br>
<br>
-Ben<br></div></div>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" target="_blank">https://mail.python.org/mailman/options/python-dev/guido%40python.org</a><span><font color="#888888"><br>
</font></span></blockquote></div><span><font color="#888888"><br><br clear="all"><br>-- <br><div>--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</font></span></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div>--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>
</div></div></blockquote></div><br></div>