<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 13, 2013 at 10:39 AM, Juancarlo Añez <span dir="ltr"><<a href="mailto:apalala@gmail.com" target="_blank">apalala@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="gmail_extra"><div class="im"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>If you want something different to this, then I think you do want new syntax. Otherwise, what do you gain beyond what can already be done now?<br>


<br>
Or am I missing something?</div></blockquote></div><br></div>It's not obvious from my example, but the idea is that the invoker be able to provide context for _each_ iteration.</div><div class="gmail_extra"></div></blockquote>

</div><br>I can explain better. While parsing a closure, the parser knows it should stop iterating because the embedded expression fails to parse midway. At that point, the last iteration must be rolled back (rewind the input stream and discard syntax tree nodes). To roll back just the last iteration, the iterator needs to control the context for each iteration, because it can't predict which will be the last, the one to fail.</div>

<div class="gmail_extra"><br></div><div class="gmail_extra">The above works perfectly defining a function for the embedded expression using a synthetic name, like "c123", and passing it to closure():<br><br><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">

<div class="gmail_extra" style>def c123():<br>    match_this()<br>    match_that()</div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra" style>closure(c123)</div></blockquote>

<blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra" style><br></div></blockquote><div class="gmail_extra" style>My quest is because the above seems quite unpythonic.</div><div class="gmail_extra" style>

<br></div><div class="gmail_extra" style><span style="font-family:arial,sans-serif;font-size:13px;white-space:nowrap">Lakshmi suggested this pattern, which I think is an improvement:</span><br></div><div class="gmail_extra" style>

<span style="font-family:arial,sans-serif;font-size:13px;white-space:nowrap"><br></span></div><div class="gmail_extra" style><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra">with closure() as c:<br>

    @c.exp<br>    def expre():<br>        match_this()<br>        match_that()</div></blockquote></div><div class="gmail_extra"><br></div><div class="gmail_extra" style>What I think would be great is to have the action (closure) precede an anonymous block.</div>

<div class="gmail_extra" style><br></div><div class="gmail_extra" style><div class="gmail_extra"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra">closure(<br>    def():<br>        match_this()<br>

        match_that()</div><div>)</div></blockquote></div></div><div class="gmail_extra" style><br></div><div style>Cheers,</div><div style><br></div>-- <br><span style="color:rgb(0,102,0)">Juancarlo </span><b style="color:rgb(0,102,0)">Añez</b>
</div></div>