Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'languages.': 0.04; 'syntax': 0.04; '21,': 0.07; 'expressions': 0.07; 'ugly': 0.07; 'content:': 0.09; 'function,': 0.09; 'line:': 0.09; 'references.': 0.09; 'statements': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'def': 0.12; 'language,': 0.12; 'ah,': 0.16; 'beautifully': 0.16; 'dict': 0.16; 'displays,': 0.16; 'expression,': 0.16; 'expression.': 0.16; 'flow.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'introduces': 0.16; 'lambda': 0.16; 'season.': 0.16; 'subject:?)': 0.16; 'way;': 0.16; 'wrote:': 0.18; "python's": 0.19; 'thu,': 0.19; 'example': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'fairly': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'read,': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'feature': 0.29; "doesn't": 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'anonymous': 0.31; 'option.': 0.31; 'restricted': 0.31; 'anyone': 0.31; 'this.': 0.32; 'regular': 0.32; 'becomes': 0.33; 'style': 0.33; 'totally': 0.33; 'sense': 0.34; "i'd": 0.34; 'subject: (': 0.35; 'something': 0.35; 'definition': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'much.': 0.36; 'done': 0.36; 'next': 0.36; 'being': 0.38; 'pm,': 0.38; 'extremely': 0.39; 'support,': 0.39; 'either': 0.39; 'how': 0.40; 'even': 0.60; 'break': 0.61; 'full': 0.61; 'new': 0.61; "you'll": 0.62; 'high': 0.63; 'more': 0.64; 'here': 0.66; 'close': 0.67; 'content,': 0.68; 'again!': 0.84; 'pike': 0.84; 'toy': 0.84; 'to:none': 0.92; 'serious': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=xkU00LFNlBCwTYYPn8iOW0F0p0/273xhPfUof7CNXxU=; b=IHwFD1/lMxdlCIG/T2UxkjNf6v0VNn/U7xBGhAXZjmeGFqKp3VqU0GELhZs7mlfyML tZqDpBVPd/U+iyei6pYJpngcXLI1ktGUAni/+7QMnxk6G6U+82hUKZ9uja57C6RBpOxo zA2hGn5TT5IXTvUkGtEmtAxpSHerZcPw3BSqnb/v5LDw5ginwptNXfNdJoXoL9P22gn6 PgORihRbu6v9Bl2MDUpHzaVQA7QbXcEzWiudt0kbJkyDBD0nsQRXYEEusaBZdTBoCoV8 5ABCobm90/m+MQXYuV+Cb0OEup8H5k0anjlW1cR6DvbCR7YUlV//ygQcA+td16a+waGi LX+A== MIME-Version: 1.0 X-Received: by 10.42.201.134 with SMTP id fa6mr99572icb.73.1408609094570; Thu, 21 Aug 2014 01:18:14 -0700 (PDT) In-Reply-To: <1bd05b41-ad00-4ce8-8678-de51205ebc3b@googlegroups.com> References: <1bd05b41-ad00-4ce8-8678-de51205ebc3b@googlegroups.com> Date: Thu, 21 Aug 2014 18:18:14 +1000 Subject: Re: proposed syntax for multiline anony-functions (hopefully?) From: Chris Angelico Cc: "python-list@python.org" 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: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1408609103 news.xs4all.nl 2941 [2001:888:2000:d::a6]:49148 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:76718 Ah, here we go again! It's multi-line lambda season. Comes around as regularly as duck-typing season, rabbit seasoning, baseball season, and other Looney Tunes references. :) On Thu, Aug 21, 2014 at 5:55 PM, wrote: > doFunc(def(): > print( "anon" ) > return "gvr") What I'm seeing here is that "def():" introduces a suite which becomes a function definition that's part of the current expression. That's reasonable, but I don't like the close parens on the same line; even if this syntax is allowed, I'd frown on it in style guides, recommending the close parens go on the next line: doFunc(def(): print( "anon" ) return "gvr" ) But either way, the question you need to answer is: How is this better than the regular syntax for named functions? def tmp(): print( "anon" ) return "gvr" doFunc(tmp) The one use-case that I can think of is large expressions like dict displays, but I'd like to see a serious example that actually needs this. Here's a toy example: tag_handler = { "span": lambda content: content, "div": lambda content: "\n"+content+"\n", "p": lambda content: "\n"+content+"\n", "br": lambda content: "\n", } If you wanted to expand one of those to have statements in it, you'd have to take it out-of-line and break the flow. But this is totally contrived and not real-world; before this sort of feature gets into the language, there really needs to be a concrete use-case. Since there's nothing that actually cannot be done with an out-of-line function, the criterion has to be "doing this out-of-line is extremely ugly or error-prone", which is a fairly high bar to reach. You'll need something where anyone will immediately say "Oh, that way is horribly hard to read, but the new way makes it beautifully clean!". Python is much more statement-oriented than some languages. In Pike, I can have a function that's syntactically a single gigantic expression, because it (occasionally!!) makes sense to do it that way; Python doesn't really give that option. So while Pike has good justification for an anonymous function syntax with full statement support, Python doesn't really call for it as much. That's why Python's survived this long with its lambda functions being so severely restricted :) ChrisA