lambdak: multi-line lambda implementation in native Python
Ian Kelly
ian.g.kelly at gmail.com
Thu Jan 15 01:39:09 EST 2015
On Wed, Jan 14, 2015 at 11:06 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> I have a function, which I put into an expression like this:
>
> def func(a, b=None):
> global spam
> import math
> spam = [a, b]*3
> print spam
> del spam
>
>
> value = [1, "hello", int, func]
> del func
>
> How would I use lambdak to write that as an expression
>
> value = [1, "hello", int, ??????? ]
>
> without the intermediate def?
# Untested, but seems like this should work.
value = [1, "hello", int, given_(lambda a, b=None:
import_("math", lambda math:
import_("operator", lambda operator:
do_(lambda: operator.setitem(globals(), 'spam', [a, b]*3), lambda:
print_(globals()['spam'], lambda:
do_(lambda: operator.delitem(globals(), 'spam')))))))]
To the OP: I note that although import_ is used in the examples, it's
not found in the list of functions in the README.
More information about the Python-list
mailing list