<div dir="ltr">[Jonathan Fine]<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 have reservations about the name lambda. But there's a lot of<br></span><span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">code out there that uses lambda, and I'd like that code to continue to<br></span><span style="font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">run.</span></blockquote><div><br>Yes. I'm under no delusion that lambda will be replaced any time soon. Nor do I believe any alternative I suggest will be enough of an improvement to warrant breaking the "there should be one and only one obvious way to do something rule". So I don't expect this conversation to lead to any change to the language, I just think my case that it's sub-optimal might inform future design decisions. Though it doesn't look like anyone finds it especially convincing.<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">[Jonathan Fine]</span><br style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><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">My understanding is that you prefer<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">>>> EXPRESSION with IDEN<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">to<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">>>> lambda IDEN: EXPRESSION</span></blockquote><br>Correct. My argument is two fold: <br><br>1) the name "lambda" is needlessly esoteric.<br>2) the format of lambdas is "backwards"<br><br>I tried to focus on the name gripe in this thread because trying to explain both at the same time caused confusion. However, Stephen Turnbull's and (more so) Steven D'Aprano's comments made the format argument semi-relevant and I can't help getting on that soap-box...<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">[Jonathan Fine]</span><br style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><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">How do you feel about this, as a means of defining an anonymous function?<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">>>> with IDEN: EXPRESSION</span></blockquote><div><br>I think it's better than lambda. I can't decide if I like it more than:<br><br><font face="monospace, monospace">>>> def IDEN: EXPRESSION</font><br><br>Because def is more clearly connected to function declaration and i'm somewhat sympathetic to the idea of expressionizing "with"-statements.<br>The only reason I don't prefer:<br><br><font face="monospace, monospace">>>> EXPRESSION def IDEN</font><br><br>to <br><br><font face="monospace, monospace">>>> EXPRESSION with IDEN</font><br><br>Is that it looks weird to me. It just doesn't seem right.<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">Jonathan Fine]</span><br style="font-size:12.8px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><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">Now for a trick question. Consider<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">>>> fn =  (lambda : EXPRESSION)<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">This produces a function that has zero parameters.</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">How would you write this, using 'with'. Would it be:<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">>>> fn = (EXPRESSION with)<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">I think this looks rather odd.</span></blockquote><br>That's a good point. I hadn't considered that. There are several possible formats that put the expression before the signature definition. The specific form isn't quite as interesting to me. I would even prefer something like:<br><br><font face="monospace, monospace">>>> def (EXPRESSION [<seperator> SIG])</font><br><br>Mostly because "def" could then have a double meaning: "define" and "deferred expression". I think that's kinda neat. My problem with putting the signature first is that it usually amounts to noisy preamble that gets in the way of the important code. In pseudo code you'd often write:<br><br><font face="monospace, monospace">>>> hand = sorted(cards, by=card.suit)</font><br><br>But obviously the compiler doesn't know what "card" is since it's never declared, so we write:<br><br>>>> hand = sorted(cards, by=lambda card: card.suit)<br><br>Notice that the information that's important to the reader: the expression, is pushed behind information the computer needs but the reader probably doesn't care about.<br>My claim is that in most cases, the signature is more noise than signal, so it should come after the expression.<br><br>A function passed as a callback, key-function, mapper, reducer, filter, event handler, etc. has a mostly pre-defined call signature. In most other cases, you're better off using a named function.<br><br>Thanks for your input!</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 21, 2018 at 3:51 PM, Jonathan Fine <span dir="ltr"><<a href="mailto:jfine2358@gmail.com" target="_blank">jfine2358@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Abe<br>
<br>
First, I have reservations about the name lambda. But there's a lot of<br>
code out there that uses lambda, and I'd like that code to continue to<br>
run.<br>
<span class=""><br>
You wrote:<br>
> func = value[card.suit] if card not in wilds else wild_value with card<br>
<br>
</span>I thought I'd try this, and variants, in the Python interpreter. I got<br>
<br>
# An expression. It's valid syntax, get run-time error.<br>
<span class="">>>> value[card.suit] if card not in wilds else wild_value<br>
</span>NameError: name 'card' is not defined<br>
<br>
# An expression. It's valid syntax. Its value is a function. No run-time error.<br>
>>> lambda card: value[card.suit] if card not in wilds else wild_value<br>
<function <lambda> at 0x7ff815e2bbf8><br>
<br>
# If Python were enhanced, an valid expression whose value is a function.<br>
<span class="">>>> value[card.suit] if card not in wilds else wild_value with card<br>
</span>SyntaxError: invalid syntax<br>
<br>
My understanding is that you prefer<br>
>>> EXPRESSION with IDEN<br>
to<br>
>>> lambda IDEN: EXPRESSION<br>
<br>
How do you feel about this, as a means of defining an anonymous function?<br>
>>> with IDEN: EXPRESSION<br>
<br>
We can't adopt it, of course, because it's already valid syntax, but<br>
with semantics.<br>
<br>
>>> with wibble:<br>
...    wobble<br>
NameError: name 'wibble' is not defined<br>
<br>
Now for a trick question. Consider<br>
>>> fn =  (lambda : EXPRESSION)<br>
This produces a function that has zero parameters.<br>
<br>
How would you write this, using 'with'. Would it be:<br>
>>> fn = (EXPRESSION with)<br>
I think this looks rather odd.<br>
<span class="HOEnZb"><font color="#888888"><br>
-- <br>
Jonathan<br>
</font></span></blockquote></div><br></div>