Path: csiph.com!usenet.pasdenom.info!news.franciliens.net!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'operator': 0.03; 'explicitly': 0.05; 'indexing': 0.07; 'branching': 0.09; 'implements': 0.09; 'subject:test': 0.09; 'python': 0.11; '23,': 0.16; 'conditional': 0.16; 'evaluating': 0.16; 'lambda': 0.16; 'lambda:': 0.16; 'relates': 0.16; 'ternary': 0.16; 'language': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'translated': 0.19; 'meant': 0.20; '>>>': 0.22; 'purposes': 0.26; 'right.': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'branches': 0.31; 'purely': 0.31; 'lists': 0.32; 'selection': 0.32; 'actual': 0.34; 'sense': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'in.': 0.36; 'opposed': 0.36; 'done': 0.36; 'shows': 0.36; 'application': 0.37; 'to:addr:python-list': 0.38; 'rather': 0.38; 'does': 0.39; 'functional': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'expression': 0.60; 'first': 0.61; 'applying': 0.72; 'subject::': 0.85; 'calculus': 0.91; 'technique': 0.93 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=VLqzLlLCnErRhv3F/cUnkriunby8ZR4lwiPx7AmoX9E=; b=icHOIgZngRiqJWJRpu+1osXvBaTAa+HvMUmXZgKNTyZdCZyCkjkySpNXyzKJW/tcRA /KdCtOUTrNOm6b7VjNZHJ3//ai2QJ8qpw/7b1n3ZPf5RLUR8FcsI6XkbAoebnQPH1OJ1 UfHJcVftHHnICw++53MxXA9VxbZjoWNhMbBPlITWCWi3sws53fH11kl63aFVppkZ8AJy wZFBQmlKYA1QJPZbgZzS8OeY+Fy1xJh9H+8oh+OzxlK7jq9JeH273ZRUWGTiKolM+asQ pOUlaOqtSG0aNQg/fucnPEWkb5EvBQtLybiB02HZVyYD8X6x1js8ZAnYRPd0rSCYVtQ4 0eiQ== X-Received: by 10.66.255.7 with SMTP id am7mr3920097pad.134.1414074288753; Thu, 23 Oct 2014 07:24:48 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <878uk6x5nd.fsf@elektro.pacujo.net> References: <54476af8$0$21651$426a74cc@news.free.fr> <7839376e-fc27-4299-ae63-4ddf17ef9a8a@googlegroups.com> <7d2ea3c1-504e-4f5c-8338-501b1483df38@googlegroups.com> <878uk6x5nd.fsf@elektro.pacujo.net> From: Ian Kelly Date: Thu, 23 Oct 2014 08:24:07 -0600 Subject: Re: (test) ? a:b 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414074297 news.xs4all.nl 2952 [2001:888:2000:d::a6]:36345 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 938280954 X-Received-Bytes: 5004 Xref: csiph.com comp.lang.python:79521 On Thu, Oct 23, 2014 at 7:44 AM, Marko Rauhamaa wrote: > However, the "[f, g][cond]()" technique is how pure lambda calculus > implements conditional branching so it is interesting in its own right. I wasn't aware that lambda calculus had lists and indexing built in. > IOW, you can do "short-circuiting" in purely functional programming: > > j = j + 1 if j < 10 else 3 > > <=> > > j = (lambda: 3, lambda: j + 1)[j < 10]() The implementation given by Wikipedia (and translated into Python by me) is: >>> true = lambda x: lambda y: x >>> false = lambda x: lambda y: y >>> ifthenelse = lambda p: lambda a: lambda b: p(a)(b) >>> ifthenelse(true)(1)(2) 1 >>> ifthenelse(false)(1)(2) 2 For demonstration purposes I used Python ints as the branches rather than actual lambda calculus constructs, but this shows how selection can be done using only lambda abstractions and applications. In any case I don't see how this relates to the "[f, g][cond]()" technique of Python, unless you just meant the general approach of first selecting a function and then applying it. In that sense though, the ternary operator does the same thing; the application is just done invisibly by the language in the form of evaluating an expression as opposed to explicitly applying a function.