<div dir="ltr">[Stephen Turnbull]<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I was an economist then, and I'm an economist still, but I met lambda<br></span><span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">in 1977. Surely lambda has had that role in computer languages since<br></span><span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">shortly before I was born.</span></blockquote><div> </div><div>According to <a href="https://en.wikipedia.org/wiki/Anonymous_function">Wikipedia</a> Lisp was the first language to use anonymous functions (introduced in 1958).<br><br><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">[Stephen Turnbull]<br></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I would guess anybody above a certain age<br></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">would reach for "lambda" first for a keyword to denote or define an<br></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">anonymous function. Not because of the lambda calculus, but because<br></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">of Lisp.</span></blockquote><div><br>Wikipedia lists the <a href="https://en.wikipedia.org/wiki/Anonymous_function#Examples">anonymous function syntax of 40+ languages</a> and only 5 (Lisp, Scheme, Python, Ruby, and Maxima) use the "lambda" keyword.<br>Haskel uses a "\" which I'm pretty sure is supposed to look like the lambda symbol, but even that syntax seems unpopular too.<br><br><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">[Stephen Turnbull]</span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Maybe there's a better word than "regret". After all, It's<br></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">hard to see how you could prototype range better than "range([START,]<br></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">END, [STRIDE])", and the same might be true for "def [NAME] ([ARG0,]<br></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">...):".</span></blockquote><div><br>I wasn't aware that Guido considered "range" to be warty. I like the way it mimics slicing syntax. It makes it easy for me to remember. It seems like a very pragmatic design.<br><br>[Steven D'Aprano]<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Secure in the knowledge that Guido probably isn't reading this and won't<span> <br></span></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">contradict me *wink* I'm going to try channelling him.</span></blockquote><div><br>SUMMON THE GREAT CREATOR!<br><br>I wonder if I say his name three times...<br>Guido Van Rossum! Guido Van Rossum! Guido Van Rossum!<br><br><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">[Steven D'Aprano]<br></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I think he would<span> </span></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">regret "def expressions", but not because of the range reason.</span> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I think<span> </span></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">its because he likes the relatively strict demarcation between<span> </span></span><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">statements and expressions.</span><br style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">We have 4 statements that have a expression form:</span><br style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">if...else versus ternary if expressions;</span><br style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">for loops versus comprehensions;</span><br style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">(soon) = assignment versus := assignment expressions; and</span><br style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">def versus lambda.</span></blockquote><br>(I don't know why Gmail's quotes screw up formatting...)<br><br>I don't think that's the reason those expressions have different formats than their statement counterparts.<br>Expressions allow for more flexible arrangement than expressions because the order of execution of an expression doesn't have to follow the order of declaration.<br>While it's more natural to say "do something to each item in this collection that meets some condition" you can't access variables before they're declared in statements<br>so you have to tell the computer explicitly that you're looping over some iterable first. Expressions allow you to be more expressive.<br><br>You don't have to put your edge-case checking up-front and in the way. When 99.9% of the time you just want:<br><br><font face="monospace, monospace">x = y</font><br><br>you can shove the edge-case checking to the side and let the core logic shine:<br><br><font face="monospace, monospace">x = y if not edge_case else special_value</font><br><br><font face="monospace, monospace"># extra spaces added for emphasis<br></font><br>besides:<br><br><span style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><font face="monospace, monospace">result = if condition expression else expression</font><br></span><br>is super awkward to read out loud. That's not how I think at least.<br>I've never hears someone say, "My child's name will be if it's a girl Sally otherwise Billy."<br><br>All of the expressions use either the same or similar keywords or symbols *except* def and lambda.<br><br><font face="monospace, monospace">func = def <args>: <expression> <br></font><br>Is about as different from the statement form as "x := y" is from "x = y". No name, no parentheses for the arguments.<br>Finally, I know you've heard the other half of my anti-lambda manifest, but I don't know if Stephen Turnbull has, so I'll briefly present it again.<br><br>It's not just the name "lambda" that bothers me, it's the arrangement of the logic and signature. I believe that the expressiveness that allows comprehensions to put the core logic in front of the less important (for readability) loop and filtering constructs, anonymous functions could have been arranged to put the logic in front of the (almost always) less important signature. The reason I say the signature is almost always less important is because one almost always uses an anonymous functions as an argument (key-function, callback, map, reduce, filter, etc.) to something that already defines the call signature it expects.<br><br>Consider the alternate form: <font face="monospace, monospace"><expression> with <args> (thought there are many alternative possibilities)<br></font><br><font face="monospace, monospace">hand = sorted(cards, key=lambda card: value[card.suit] if card is not wild else max_value)<br><br>hand = sorted(cards, by=value[card.suit] if card is not wild else max_value with card)</font></div><div><font face="monospace, monospace"> </font></div><div><font face="monospace, monospace"># notice how unsurprising it is that the signature is "card"</font><br><br>Oh wait... Did I accidentally replace "key" with "by"? Huh... It seems to make more sense even though the jargon is a "key function"... Oops! ;)<br><br>Note: if this were a full proposal, lambdas with complex arguments or in certain situations would require parens: <font face="monospace, monospace">(<expression> with <args>)</font></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 21, 2018 at 9:31 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue, Aug 21, 2018 at 02:07:33PM +0900, Stephen J. Turnbull wrote:<br>
<br>
> I was an economist then, and I'm an economist still, but I met lambda<br>
> in 1977. Surely lambda has had that role in computer languages since<br>
> shortly before I was born. I would guess anybody above a certain age<br>
> would reach for "lambda" first for a keyword to denote or define an<br>
> anonymous function. Not because of the lambda calculus, but because<br>
> of Lisp. (OK, that's indirectly because of the lambda calculus.)<br>
<br>
</span>Its pretty much a term of art.<br>
<br>
(Aside: "term of art" is itself a term of art:<br>
<a href="https://legal-dictionary.thefreedictionary.com/Term+of+Art" rel="noreferrer" target="_blank">https://legal-dictionary.<wbr>thefreedictionary.com/Term+of+<wbr>Art</a> )<br>
<br>
<br>
I think that complaining about lambda is like complaining about "3-sigma <br>
versus 6-sigma processes" in process management. (Not computer <br>
processes, manufacturing processes and quality control.) Or for that <br>
matter, "mean" and "standard deviation" in statistics.<br>
<br>
The main difference is that most people are introduced to mean and stdev <br>
in secondary school, while functional programming idioms and lambda are <br>
generally stumbled across in the field. (I know that's how I learned of <br>
the term: through Python.)<br>
<span class=""><br>
<br>
> Had Guido decided to change it to "def", I suspect he'd be regretting<br>
> it slightly today, for reasons similar to the regrets about "range":<br>
> we normally only allow omitting positional arguments at the end of the<br>
> list. Maybe there's a better word than "regret". After all, It's<br>
> hard to see how you could prototype range better than "range([START,]<br>
> END, [STRIDE])", and the same might be true for "def [NAME] ([ARG0,]<br>
> ...):".<br>
<br>
</span>Secure in the knowledge that Guido probably isn't reading this and won't <br>
contradict me *wink* I'm going to try channelling him. I think he would <br>
regret "def expressions", but not because of the range reason. I think <br>
its because he likes the relatively strict demarcation between <br>
statements and expressions.<br>
<br>
We have 4 statements that have a expression form:<br>
<br>
if...else versus ternary if expressions;<br>
<br>
for loops versus comprehensions;<br>
<br>
(soon) = assignment versus := assignment expressions; and<br>
<br>
def versus lambda.<br>
<br>
(Did I miss any? I don't include technicalities like dot attribute <br>
access versus getattr and similar.) It's notable that in none of those <br>
cases the syntax is quite the same in the two forms. There's always <br>
enough differentiation between the statement and expression that there's <br>
never any ambiguity which is intended. We don't have:<br>
<br>
result = if condition expression else expression<br>
<br>
where it is the lack of colons which hints that it is an expression, we <br>
have a completely different syntax. So I think Guido probably wouldn't <br>
like the idea of using def in expressions:<br>
<br>
def function(arg, callback=def: None):<br>
pass<br>
<br>
<br>
That's my guess, for what it's worth.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
-- <br>
Steve<br>
</font></span><div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</div></div></blockquote></div><br></div>