On 2/23/21 7:57 AM, Paul Sokolovsky wrote:
Hello,
On Tue, 23 Feb 2021 23:29:33 +1100 Steven D'Aprano
wrote: On Tue, Feb 23, 2021 at 11:27:12AM +0100, Stéfane Fermigier wrote:
Also: I know there are several modern computer languages that use arrows to represent anonymous functions (JS, Kotlin, Scala...). Javascript: first release was 1995, making it 25 years old. It's older than most Javascript programmers.
Kotlin is only 9 years old. But Scala is 17 years old.
(By the way, Julia calls the -> arrow "the stab operator". I think that's amusing.)
Python has a long history of taking inspiration from other languages, but we've had anonymous functions for longer than Javascript has existed. This proposed arrow function would just be an alternative spelling for the same thing. It adds no more power, and no more expressiveness to the language.
It would be just one more thing to learn, one more decision to make ("lambda or arrow?"), one more question to be asked a thousand times ("what's the difference between lambda and arrow?"). So, (unlike JS) we should make sure that there's no (semantic) difference between lambda and arrow functions, and the answer to "which?" should be "what you want or whatever your boss says".
(Btw, syntactically, there may be difference. I hope that we'll eventually extend lambda to multiline, I'm not so sure about arrow. Of course, with braces syntax variant both will be multiline).
My first thought to the idea of making an alternate syntax is the line from the Zen: There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. This says that if the 'arrow' is a new alternate way of writing lambda, then lambda needs to be, at least informally, deprecated and declared not to be that obvious way to do it (but it can't be actually removed for a long time for backwards compatibility reasons). Note, I thought that lambda was currently 'multi-line', it just isn't multi-statement, just a single expression, that could flow to following lines (and since often used inside a function call, being inside the '(' makes the continuation to the next line automatic) -- Richard Damon