Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '__name__': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'jan': 0.12; 'attributes.': 0.16; "name=''):": 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'res': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'work,': 0.20; 'import': 0.22; 'header:User-Agent:1': 0.23; 'math': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'subject:list': 0.30; 'subject:that': 0.31; 'version:': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'name:': 0.61; 'received:173': 0.61; 'email addr:gmail.com': 0.63; 'name': 0.63; 'skip:n 10': 0.64; 'more': 0.64; 'here': 0.66; 'subject:there': 0.68; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Is there a function that applies list of functions to a value? Date: Fri, 30 Aug 2013 00:38:55 -0400 References: <90afb50e-7932-4e05-a90d-7005e1de91b8@googlegroups.com> <4544ac21-e36f-4d9e-8972-8f6a41e629ef@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 In-Reply-To: <4544ac21-e36f-4d9e-8972-8f6a41e629ef@googlegroups.com> 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377837555 news.xs4all.nl 15920 [2001:888:2000:d::a6]:56429 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53273 On 8/29/2013 5:48 PM, fp2161@gmail.com wrote: > Here is the generalisable version: > > def comp(*func): > def anon(x): > res=x > for f in func: > res=f(res) > return res > return anon With a bit more work, one can set the __name__ and __qualname__ attributes. import math as m def comp(*func, name=''): def anon(x): res=x for f in func: res=f(res) return res if name: anon.__name__ = name q = anon.__qualname__.rsplit('.', maxsplit=1) q[1] = name anon.__qualname__ = '.'.join(q) return anon esincos = comp(m.exp, m.sin, m.cos, name='esincos') print(esincos) # .esincos at 0x00000000033107B8> -- Terry Jan Reedy