lambdak: multi-line lambda implementation in native Python
steve+comp.lang.python at pearwood.info
Thu Jan 15 15:29:22 CET 2015
Ian Kelly wrote:
> On Wed, Jan 14, 2015 at 11:06 PM, Steven D'Aprano <steve at pearwood.info>
>> 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')))))))]
Thank you for showing me that.
Now I shall try very hard to forget I ever saw it.
*shudders at the thought of maintaining such a beast*
More information about the Python-list