A RetroSearch Logo

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

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20110408/ca5ccc59/attachment.html below:

<div class="gmail_quote">On Fri, Apr 8, 2011 at 10:50 AM, David Malcolm <span dir="ltr">&lt;<a href="mailto:dmalcolm@redhat.com">dmalcolm@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Fri, 2011-04-08 at 21:29 +1000, Nick Coghlan wrote:<br>
&gt; A few odds and ends from recent discussions finally clicked into<br>
&gt; something potentially interesting earlier this evening. Or possibly<br>
&gt; just something insane. I&#39;m not quite decided on that point as yet (but<br>
&gt; leaning towards the latter).<br>
<br>
</div>I too am leaning towards the latter (I&#39;m afraid my first thought was to<br>
check the date on the email); as Michael said, I too don&#39;t think it<br>
<div class="im">stands much of a chance in core.<br>
<br>
</div><div class="im">&gt; Anyway, without further ado, I present:<br>
&gt;<br>
&gt; AST Transformation Hooks for Domain Specific Languages<br>
&gt; ======================================================<br>
<br>
</div>This reminds me a lot of Mython:<br>
  <a href="http://mython.org/" target="_blank">http://mython.org/</a><br>
If you haven&#39;t seen it, it&#39;s well worth a look.<br>
<br>
My favourite use case for this kind of thing is having the ability to<br>
embed shell pipelines into Python code, by transforming bash-style<br>
syntax into subprocess calls (it&#39;s almost possible to do all this in<br>
regular Python by overloading the | and &gt; operators, but not quite).<br>
<div class="im"><br>
&gt; Consider:<br>
&gt;<br>
&gt; # In some other module<br>
&gt; ast.register_dsl(&quot;dsl.sql&quot;, dsl.sql.TransformAST)<br>
<br>
</div>Where is this registered?   Do you have to import this &quot;other module&quot;<br>
before importing the module using &quot;dsl.sql&quot; ?   It sounds like this is<br>
global state for the interpreter.<br>
<div class="im"><br>
&gt; # In a module using that DSL<br>
<br>
</div>How is this usage expressed?  via the following line?<br>
<br>
&gt; import dsl.sql<br>
<br>
I see the &quot;import dsl.sql&quot; here, but surely you have to somehow process<br>
the &quot;import&quot; in order to handle the rest of the parsing.<br>
<br>
This is reminiscent of the &quot;from __future__ &quot; specialcasing in the<br>
parser.  But from my understanding of CPython&#39;s Python/future.c, you<br>
already have an AST at that point (mod_ty, from Python/compile.c).<br>
There seems to be a chicken-and-egg problem with this proposal.<br>
<br>
Though another syntax might read:<br>
<br>
  from __dsl__ import sql<br>
<br>
to perhaps emphasize that something magical is about to happen.<br>
<br>
[...snip example of usage of a DSL, and the AST it gets parsed to...]<br>
<br>
Where and how would the bytes of the file usage the DSL get converted to<br>
an in-memory tree representation?<br>
<br>
IIRC, manipulating AST nodes in CPython requires some care: the parser<br>
has its own allocator (PyArena), and the entities it allocates have a<br>
shared lifetime that ends when PyArena_Free occurs.<br>
<div class="im"><br>
&gt; So there you are, that&#39;s the crazy idea. The stoning of the heretic<br>
&gt; may now commence :)<br>
<br>
</div>Or, less violently, take it to python-ideas?  (though I&#39;m not subscribed<br>
there, fwiw, make of that what you will)<br>
<br>
One &quot;exciting&quot; aspect of this is that if someone changes the DSL file,<br>
the meaning of all of your code changes from under you.  This may or may<br>
not be a sane approach to software development :)<br>
<br>
(I also worry what this means e.g. for people writing text editors,<br>
syntax highlighters, etc; insert usual Alan Perlis quote about syntactic<br>
sugar causing cancer of the semicolon)<br>
<br>
Also, insert usual comments about the need to think about how<br>
non-CPython implementations of Python would go about implementing such<br>
ideas.<br>
<div class="im"><br>
&gt; Where this idea came from was the various discussions about &quot;make<br>
&gt; statement&quot; style constructs and a conversation I had with Eric Snow at<br>
&gt; Pycon about function definition time really being *too late* to do<br>
&gt; anything particularly interesting that couldn&#39;t already be handled<br>
&gt; better in other ways. Some tricks Dave Malcolm had done to support<br>
&gt; Python level manipulation of the AST during compilation also played a<br>
&gt; big part, as did Eugene Toder&#39;s efforts to add an AST optimisation<br>
&gt; step to the compilation process.<br>
<br>
</div>Like I said earlier, have a look at Mython<br>
<br>
Hope this is helpful<br>
Dave<br>
<div><div></div><div class="h5"><br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/ericsnowcurrently%40gmail.com" target="_blank">http://mail.python.org/mailman/options/python-dev/ericsnowcurrently%40gmail.com</a></div></div></blockquote>
<div><br></div><div>Someone brought up some of the same stuff in the python-ideas thread and Nick responded there, particularly about the import question.</div></div><br>

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