Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; 'intermediate': 0.07; '[1,': 0.09; 'function,': 0.09; 'def': 0.12; 'jan': 0.12; 'func': 0.16; 'lambda': 0.16; 'lambda:': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'seems': 0.21; 'import': 0.22; 'print': 0.22; 'math': 0.24; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'work.': 0.31; "skip:' 10": 0.31; "d'aprano": 0.31; 'int,': 0.31; 'steven': 0.31; 'subject:skip:i 10': 0.31; 'but': 0.35; 'received:google.com': 0.35; '14,': 0.36; 'should': 0.36; 'list': 0.37; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'expression': 0.60; '2015': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=/b5sW4Uo2NOKhNAYdd+ZLLvhJflvVkSBKzxU2ofP7yw=; b=BHStY6Syh/TOYNu+pf/vrGv9hh0fewDwqXVJn2JdQBifAKGO1cks4YZmQjPpydYrKQ qYk48kV2YV88fphHuu/Yr1uRc/RiCz8SbCkKhApMnp+s4h3DLbhlcQnG1r8Hn9LX7pMG rpARleLr+vNsmSGopZXStdzBqXHmuKDK+qaVPFLIKxLKIvTnxdb4DLBS9KxUpOl3OdI/ yZyPBA5F1vCZAdkhMKEU/Q91tbSB1+nWpVLErlPQ3Y8rr+hI3JX4QhZM3TtiRyfkA4zr RnjES4j3cqZ5zE9LewpVTamkSrNM9sJxmA1Wd8eSV/zkrT+OM4Cb/9ag2mXUe1F3oQcZ nJiA== X-Received: by 10.68.197.72 with SMTP id is8mr11876748pbc.17.1421303989524; Wed, 14 Jan 2015 22:39:49 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <54b758e1$0$2738$c3e8da3$76491128@news.astraweb.com> References: <3d8068b3-7b63-43c0-bbf2-6111b2c73aa4@googlegroups.com> <54b758e1$0$2738$c3e8da3$76491128@news.astraweb.com> From: Ian Kelly Date: Wed, 14 Jan 2015 23:39:09 -0700 Subject: Re: lambdak: multi-line lambda implementation in native Python To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1421303993 news.xs4all.nl 2915 [2001:888:2000:d::a6]:47875 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83796 On Wed, Jan 14, 2015 at 11:06 PM, Steven D'Aprano 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.