Ian Kelly wrote: > On Wed, Jan 14, 2015 at 11:06 PM, Steven D'Aprano <st...@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')))))))]
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* -- Steven -- https://mail.python.org/mailman/listinfo/python-list