Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #87982

Re: Supply condition in function call

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.122
X-Spam-Level *
X-Spam-Evidence '*H*': 0.76; '*S*': 0.00; 'compiler': 0.07; 'manuel': 0.09; 'def': 0.12; 'lambda': 0.16; 'wrote:': 0.18; 'wed,': 0.18; '>>>': 0.22; 'days,': 0.24; 'sort': 0.25; "i've": 0.25; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:wiki': 0.31; '25,': 0.31; 'url:wikipedia': 0.31; 'not.': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'url:org': 0.36; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'heard': 0.39; 'to:addr:python.org': 0.39; 'ian': 0.60; 'referred': 0.60; 'back': 0.62; 'term': 0.63; 'such': 0.63; 'mar': 0.68; 'college': 0.70; 'day': 0.76; '2015': 0.84; 'edwards': 0.91
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=EkaIBulcHU+XFvWoYkCMSbQoun7hX8Ky5cyN7lxramY=; b=NlDS+zr1I0bD1F48I27rOkBMC1Wp+P2GSPGki0+OCUavHqdUz0IAQ/Ku5FFaIT9hgy otetIqIkZ6EpsX/4lJxaFwcOI+dWBMw0h0tZ50uzqGb6rERV/pTD7aZSU6if+nsI1xZQ lsGQgpsKxfawNYKjee6D4aWQXXXWhARxvSExXxpkST3ipbU48+ZJ9KvOd7/0JF2IJvli RfQi64oFqd9u/LTFHijpPd3kevZahrj6YboqPHZL+BOFDEzxf4UX0Hp2izYdtxjezAzl a2cW8qiLH0F3Tc8y5u9/THXgeilKVntuETlIYVCp5Nao7ZBN4PWH9eEcWK/WjT/Kk6R3 GNMQ==
X-Received by 10.66.65.234 with SMTP id a10mr21125604pat.120.1427316588830; Wed, 25 Mar 2015 13:49:48 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <mev3nc$q4k$1@reader1.panix.com>
References <87bnjhyohp.fsf@uriel.graune.org> <mailman.147.1427305497.10327.python-list@python.org> <mev3nc$q4k$1@reader1.panix.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 25 Mar 2015 14:49:08 -0600
Subject Re: Supply condition in function call
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.19
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.162.1427316591.10327.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1427316591 news.xs4all.nl 2914 [2001:888:2000:d::a6]:60781
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:87982

Show key headers only | View raw


On Wed, Mar 25, 2015 at 1:53 PM, Grant Edwards <invalid@invalid.invalid> wrote:
> On 2015-03-25, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>> On Wed, Mar 25, 2015 at 11:29 AM, Manuel Graune <manuel.graune@koeln.de> wrote:
>>
>>> I'm looking for a way to supply a condition to an if-statement inside a
>>> function body when calling the function. I can sort of get what I want
>>> with using eval [...]
>>
>> Pass the condition as a function.
>>
>> def test1(a, b, condition=lambda i, j: True):
>>     for i,j in zip(a,b):
>>         c=i+j
>>         if condition(i, j):
>>             print("Foo")
>>
>> test1([0,1,2,3],[1,2,3,4], lambda i, j: i+j > 4)
>> # etc.
>
> FWIW, back in the day such a function was referred to as a "thunk"
> (particularly if it was auto-generated by a compiler that used
> pass-by-name instead of pass-by-value or pass-by-reference):
>
>   http://en.wikipedia.org/wiki/Thunk
>
> Dunno if people still use that term or not.

I've heard the term (though not since my college days, I think), but
I've always understood thunks to be parameterless (hence the use as a
form of pass-by-name).

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Supply condition in function call Manuel Graune <manuel.graune@koeln.de> - 2015-03-25 18:29 +0100
  Re: Supply condition in function call Joel Goldstick <joel.goldstick@gmail.com> - 2015-03-25 13:41 -0400
    Re: Supply condition in function call Manuel Graune <manuel.graune@koeln.de> - 2015-03-25 18:51 +0100
      Re: Supply condition in function call Joel Goldstick <joel.goldstick@gmail.com> - 2015-03-25 14:17 -0400
      Re: Supply condition in function call Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-25 12:22 -0600
      Re: Supply condition in function call Joel Goldstick <joel.goldstick@gmail.com> - 2015-03-25 14:42 -0400
  Re: Supply condition in function call Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-25 11:44 -0600
    Re: Supply condition in function call Grant Edwards <invalid@invalid.invalid> - 2015-03-25 19:53 +0000
      Re: Supply condition in function call Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-25 14:49 -0600
        Re: Supply condition in function call Grant Edwards <invalid@invalid.invalid> - 2015-03-26 15:41 +0000
  Re: Supply condition in function call Terry Reedy <tjreedy@udel.edu> - 2015-03-25 14:50 -0400
  Re: Supply condition in function call Gary Herron <gherron@digipen.edu> - 2015-03-25 12:13 -0700
    Re: Supply condition in function call Rustom Mody <rustompmody@gmail.com> - 2015-03-25 21:02 -0700
      Re: Supply condition in function call Chris Angelico <rosuav@gmail.com> - 2015-03-26 17:00 +1100
        Re: Supply condition in function call Rustom Mody <rustompmody@gmail.com> - 2015-03-26 18:41 -0700
          Re: Supply condition in function call Chris Angelico <rosuav@gmail.com> - 2015-03-27 12:56 +1100
            Re: Supply condition in function call Rustom Mody <rustompmody@gmail.com> - 2015-03-26 19:21 -0700
              Re: Supply condition in function call Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-27 15:34 +1100
                Re: Supply condition in function call Rustom Mody <rustompmody@gmail.com> - 2015-03-27 06:48 -0700
                Re: Supply condition in function call Chris Angelico <rosuav@gmail.com> - 2015-03-28 01:17 +1100
                Re: Supply condition in function call Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-27 16:00 +0000
                Re: Supply condition in function call Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-28 18:32 +1100
                Re: Supply condition in function call Chris Angelico <rosuav@gmail.com> - 2015-03-28 18:45 +1100
            Re: Supply condition in function call Larry Hudson <orgnut@yahoo.com> - 2015-03-27 17:26 -0700
              Re: Supply condition in function call Rustom Mody <rustompmody@gmail.com> - 2015-03-27 18:27 -0700
              Re: Supply condition in function call Marko Rauhamaa <marko@pacujo.net> - 2015-03-28 09:50 +0200
                Re: Supply condition in function call Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-28 20:17 +1100
                Re: Supply condition in function call Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-28 03:19 -0600
                Re: Supply condition in function call Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-28 20:57 +1100
                Re: Supply condition in function call Cameron Simpson <cs@zip.com.au> - 2015-03-30 09:35 +1100
                Re: Supply condition in function call Manuel Graune <manuel.graune@koeln.de> - 2015-03-30 00:46 +0200
          Re: Supply condition in function call Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-26 20:25 -0600
            Re: Supply condition in function call Rustom Mody <rustompmody@gmail.com> - 2015-03-26 19:46 -0700
    Re: Supply condition in function call Manuel Graune <manuel.graune@koeln.de> - 2015-03-26 07:27 +0100
      Re: Supply condition in function call Cameron Simpson <cs@zip.com.au> - 2015-03-26 18:06 +1100
        Re: Supply condition in function call Manuel Graune <manuel.graune@koeln.de> - 2015-03-27 21:02 +0100
          Re: Supply condition in function call Cameron Simpson <cs@zip.com.au> - 2015-03-28 09:55 +1100
      Re: Supply condition in function call Peter Otten <__peter__@web.de> - 2015-03-26 10:03 +0100
        Re: Supply condition in function call Manuel Graune <manuel.graune@koeln.de> - 2015-03-27 20:46 +0100
          Re: Supply condition in function call Peter Otten <__peter__@web.de> - 2015-03-27 21:38 +0100
  Re: Supply condition in function call smap <askme.first@thankyouverymuch.invalid> - 2015-03-28 08:58 +0000

csiph-web