<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
My objections to this are twofold:<br>
<br>
1) It looks a lot like a lot of other 'structures' in python.
It looks very much like a generator expression or a tuple, so it
isn't immediately obvious to me what you are intending (if this was
allowed syntax of course.)<br>
<br>
2) While it is nice to type that over `lambda :`, typing lambda
is no great burden, and that is already just sugar for a regular def
statement. I don't think there is much of a great need for even
more terse ways of writing an anonymous function, especially ones
with the restrictions that python currently places on them (no
statements). It just doesn't make a lot of sense to change the
syntax at this point. But I think you knew that.<br>
<br>
<div class="moz-cite-prefix">On 3/2/2016 15:01, Abe Dillon wrote:<br>
</div>
<blockquote
cite="mid:054c49e4-901f-4bd7-bc46-bf69afb091c5@googlegroups.com"
type="cite">
<div dir="ltr">I'm new here, but I know that lambda expression
syntax has probably been discussed to oblivion. I have searched
previous posts without finding anything exactly like my idea so
here it is:
<div><br>
</div>
<div class="prettyprint" style="border: 1px solid rgb(187, 187,
187); word-wrap: break-word; background-color: rgb(250, 250,
250);"><code class="prettyprint">
<div class="subprettyprint"><span style="color: #800;"
class="styled-by-prettify"># instead of this</span><span
style="color: #000;" class="styled-by-prettify"><br>
hand </span><span style="color: #660;"
class="styled-by-prettify">=</span><span style="color:
#000;" class="styled-by-prettify"> sorted</span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #000;" class="styled-by-prettify">cards</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> key</span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #008;" class="styled-by-prettify">lambda</span><font
color="#666600"><span style="color: #000;"
class="styled-by-prettify"> </span></font><span
style="color: #000;" class="styled-by-prettify">card</span><span
style="color: #660;" class="styled-by-prettify">:</span><span
style="color: #000;" class="styled-by-prettify"> card</span><span
style="color: #660;" class="styled-by-prettify">.</span><span
style="color: #000;" class="styled-by-prettify">suit</span><span
style="color: #660;" class="styled-by-prettify">)</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #800;" class="styled-by-prettify"># sort
some iterable of cards by suit</span><span style="color:
#000;" class="styled-by-prettify"><br>
<br>
</span><span style="color: #800;"
class="styled-by-prettify"># do this</span><span
style="color: #000;" class="styled-by-prettify"><br>
hand </span><span style="color: #660;"
class="styled-by-prettify">=</span><span style="color:
#000;" class="styled-by-prettify"> sorted</span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #000;" class="styled-by-prettify">cards</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> key</span><span
style="color: #660;" class="styled-by-prettify">=(</span><span
style="color: #000;" class="styled-by-prettify">card</span><span
style="color: #660;" class="styled-by-prettify">.</span><span
style="color: #000;" class="styled-by-prettify">suit </span><span
style="color: #008;" class="styled-by-prettify">from</span><span
style="color: #000;" class="styled-by-prettify"> card</span><span
style="color: #660;" class="styled-by-prettify">))</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #800;" class="styled-by-prettify"># sort
some iterable of cards by suit</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span style="color: #800;"
class="styled-by-prettify">#
|<= you can stop reading here and still have a
good sense of what the code does </span></div>
</code></div>
<div><font face="verdana, sans-serif"><br>
</font></div>
<div><br>
</div>
<div>More generally, I think a superior syntax for lambda would
be:</div>
<div><br>
</div>
<div class="prettyprint" style="border: 1px solid rgb(187, 187,
187); word-wrap: break-word; background-color: rgb(250, 250,
250);"><code class="prettyprint">
<div class="subprettyprint"><span style="color: #660;"
class="styled-by-prettify">(<</span><span
style="color: #000;" class="styled-by-prettify">expression</span><span
style="color: #660;" class="styled-by-prettify">></span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">from</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #080;" class="styled-by-prettify"><signature></span><span
style="color: #660;" class="styled-by-prettify">)</span></div>
</code></div>
<div><br>
</div>
<div>The reasons I believe that's a superior syntax are:</div>
<div><br>
</div>
<div>a) In the vast majority of use cases for lambda expressions
the call signature can be easily inferred (like in a key
function), so moving it after the expression tends to be more
readable.</div>
<div><br>
</div>
<div>b) It doesn't use the esoteric name, 'lambda' which causes
its own readability issues.</div>
<div><br>
</div>
<div>c) It should be compatible with existing code:</div>
<div><br>
</div>
<div class="prettyprint" style="border: 1px solid rgb(187, 187,
187); word-wrap: break-word; background-color: rgb(250, 250,
250);"><code class="prettyprint">
<div class="subprettyprint"><span style="color: #008;"
class="styled-by-prettify">try</span><span style="color:
#660;" class="styled-by-prettify">:</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #066;"
class="styled-by-prettify">1</span><span style="color:
#660;" class="styled-by-prettify">/</span><span
style="color: #066;" class="styled-by-prettify">0</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">except</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">Exception</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">as</span><span
style="color: #000;" class="styled-by-prettify"> e</span><span
style="color: #660;" class="styled-by-prettify">:</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">raise</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #606;" class="styled-by-prettify">ValueError</span><span
style="color: #660;" class="styled-by-prettify">()</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">from</span><span
style="color: #000;" class="styled-by-prettify"> e</span><span
style="color: #660;" class="styled-by-prettify">)</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #800;" class="styled-by-prettify"># this
is already a syntax error so implementing the proposal
won't break working code</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span
style="color: #800;" class="styled-by-prettify"># of
this form. I'm not aware of any other uses of the 'from'
keyword that would create</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span
style="color: #800;" class="styled-by-prettify">#
ambiguities</span></div>
</code></div>
<div><br>
</div>
<div>I'm not sure if this should actually be implemented, but I
wanted to share the idea anyway and get some feedback. In my
opinion 'lambda' is one of the less elegant pieces of Python
syntax not because it's restricted to a single expression, but
because the name and syntax are both detrimental to
readability.</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Python-ideas mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Python-ideas@python.org">Python-ideas@python.org</a>
<a class="moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a>
Code of Conduct: <a class="moz-txt-link-freetext" href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a></pre>
</blockquote>
<br>
</body>
</html>