<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>On Mar 4, 2014, at 17:05, João Bernardo <<a href="mailto:jbvsmo@gmail.com">jbvsmo@gmail.com</a>> wrote:</div><div><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><font face="arial, helvetica, sans-serif">* assign a bill to `a` so that `a` will evaluate to the value of the name `foo` any time that `a` is evaluated, in the scope of that evaluation</font><br>
<br><font face="courier new, monospace"> a = $foo</font><br><br><font face="arial, helvetica, sans-serif">* as above, but always plus one</font><br><br><font face="courier new, monospace"> a = $foo + 1</font><br><br>
<font face="arial, helvetica, sans-serif">* make `a` a bill that evaluates to the value of the name `foo` at the time that `a` is evaluated, in that scope, plus the value of `bar` **at the time and in the scope of the assignment to `a`**</font><br>
<br><font face="courier new, monospace"> a = $foo + bar</font><br><font face="arial, helvetica, sans-serif"></font><br></div></blockquote></div><br><br></div><div class="gmail_extra">You can do all that programmatically. No need for magic operators.<br>
</div><div class="gmail_extra">Check this module as a proof of concept: <a href="https://github.com/jbvsmo/funcbuilder">https://github.com/jbvsmo/funcbuilder</a><br><br></div><div class="gmail_extra"><span style="font-family:courier new,monospace">foo = FuncBuilder()<br>
</span></div><div class="gmail_extra"><span style="font-family:courier new,monospace">a = foo + 1<br></span></div><div class="gmail_extra"><span style="font-family:courier new,monospace"># Then evaluate a with a function call</span><br>
</div><div class="gmail_extra"><br></div><div class="gmail_extra">For it to do exactly what you want, you just need override the evaluation function (Funcbuilder.__call__) to load names from current frame locals or something.<br>
BTW, I don't recommend using that on real code because it is extremely experimental (unless you're a hipster... In this case, carry on).</div></div></div></blockquote><br><div>I posted something similar in the first of the many improving-lambda threads this month, but it had a lot of little problems and one big one.</div><div><br></div><div>The big one is that not every expression can be caught by operator overloading (foo[i] is fine, but lst[foo] isn't). And call expressions are one of the most important kinds of expression, but you can't catch that--or, rather, if you _do_ catch it, then you have no way to call the resulting object.</div><div><br></div><div>The same idea in C++ doesn't have that last problem because C++ is statically typed, and you can use an implicit cast from autolambda object to function object to get from an object whose call operator builds a call expression to one whose call operator evaluates the expression. But that doesn't work in Python. </div><div><br></div><div>I wrote a blog post that gets into this further, but I can't find the link from my phone. I included it in an earlier message in the thread.</div></body></html>