[Python-ideas] Another way to avoid clumsy lambdas, while adding new functionality
João Bernardo
jbvsmo at gmail.com
Wed Mar 5 02:05:57 CET 2014
>
> * 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
>
> a = $foo
>
> * as above, but always plus one
>
> a = $foo + 1
>
> * 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`**
>
> a = $foo + bar
>
>
You can do all that programmatically. No need for magic operators.
Check this module as a proof of concept:
https://github.com/jbvsmo/funcbuilder
foo = FuncBuilder()
a = foo + 1
# Then evaluate a with a function call
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.
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).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140304/48623a83/attachment.html>
More information about the Python-ideas
mailing list