Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'subject:Python': 0.06; 'intermediate': 0.07; '[1,': 0.09; 'function,': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'language.': 0.14; 'for,': 0.16; 'func': 0.16; 'lambda': 0.16; 'lambda:': 0.16; 'maintainable': 0.16; 'preserved': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'recipe': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'wed,': 0.18; 'seems': 0.21; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'math': 0.24; "i've": 0.25; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; '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; '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; 'received:org': 0.40; 'how': 0.40; 'expression': 0.60; 'ian': 0.60; 'entire': 0.61; 'our': 0.64; 'charset:windows-1252': 0.65; 'world': 0.66; '2015': 0.84; 'prosperity,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: lambdak: multi-line lambda implementation in native Python Date: Thu, 15 Jan 2015 17:22:16 +0000 References: <3d8068b3-7b63-43c0-bbf2-6111b2c73aa4@googlegroups.com> <54b758e1$0$2738$c3e8da3$76491128@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-92-24-222-48.ppp.as43234.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 In-Reply-To: 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: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1421342548 news.xs4all.nl 2896 [2001:888:2000:d::a6]:39231 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83839 On 15/01/2015 06:39, Ian Kelly wrote: > 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. > Just what I've been looking for, highly readable, higly maintainable Python code. Please put this up as an Activestate recipe so it's preserved for prosperity, so that the entire world can see its asthetically pleasing properties. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence