[Python-ideas] Re: Alternate lambda syntax
On Wed, Feb 17, 2021 at 11:13:08AM +1300, Greg Ewing wrote: > On 17/02/21 7:10 am, Steven D'Aprano wrote: > >"It's Greek letter, like pi that you may remember from maths > >class. In some technical computer science, the Greek L, lambda, is used > >as the symbol for functions." > > The most accurate answer seems to be "Because somebody made > a mistake transcribing a mathematics paper many years ago." :-) Not according to Alonzo Church, who at various times has stated that it was either more or less chosen at random, or that it was derived from Whitehead and Russell's x̂ (x-hat) via ∧x to λx to make it easier for the printers. Either way it wasn't a mistake, but a deliberate choice. It is really remarkable how much attention lambda gets. As far as I know, mathematicians don't ask why Hilbert chose epsilon for his epsilon calculus, and nobody ever asks where "byte" comes from. It is, apparently, a deliberate misspelling of bite, to avoid it being accidently changed to bit. But why *bite*? The first published use of "byte" apparently was in a 1956 IBM memo by Werner Buchholz: "[…] Most important, from the point of view of editing, will be the ability to handle any characters or digits, from 1 to 6 bits long. Figure 2 shows the Shift Matrix to be used to convert a 60-bit word, coming from Memory in parallel, into characters, or 'bytes' as we have called them, to be sent to the Adder serially." The memo already shows that Buchholz and IBM were thinking of multiple bits being a "word", so it's not clear why bytes. There's no ordinary sense that a collection of bits (as in "a bit of stuff") is considered "a bite". Language is fun. -- Steve ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/SAIVWEGHB33IV6UM5JN2U2C333U4P6PP/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Alternate lambda syntax
Ned Batchelder writes: > "lambda" is unnecessarily obscure. And it should be. It's really only useful as an argument. There's no advantage to foo = (x) -> 1 vs. def foo(x): return 1 except a couple of characters. So what currently looks like some_list.sort(key=lambda e: e[3].priority) would then be some_list.sort(key=(e)->e[3].priority) which is shorter but not particularly more readable (and already has a familiar meaning in C-like languages). It seems to me that two changes to def might be considered: 1. In a one-line def of the form "def foo([arglist]): return EXPR", "return" may be omitted, and the function returns the value of EXPR (rather than None as currently). (As a multiline def, EXPR would be presumed to be evaluated for side effects, and 2. As an actual argument, a one-line def is interpreted not as a positional argument, but as a keyword argument, so that in some_list.sort(def key(e): e[3].priority) the name "key" is not optional, and must match a keyword argument. I suggest 1 for "ordinary" defs as well for consistency, but evidently we could also restrict that usage to "def as keyword argument", and maintain backwards compatibility. 2 could even be independent of 1: some_list.sort(def key(e): return e[3].priority) but that seems excessively verbose. Another possible use case would be in a for loop: for fun in [def fun(): return 1, def fun(): return 2, def fun(): return 3]: do_something_with(fun) where similarly the loop variable needs to match the def. > Beginner: "why is it called lambda?" > > Teacher: "Don't worry about it, just use it to define a function" > It me. But it would go like this: Teacher [face lights up at the chance to talk math history]: "You see, ..." Students [in harmony]: "Nooo.. :-(" [collective sigh] Regards, Steve ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/2UQU33XFZFMNP4AITJXQJI3UNPYTEOW7/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Alternate lambda syntax
On 16.02.2021 23:13, Greg Ewing wrote: > On 17/02/21 7:10 am, Steven D'Aprano wrote: >> "It's Greek letter, like pi that you may remember from maths >> class. In some technical computer science, the Greek L, lambda, is used >> as the symbol for functions." > > The most accurate answer seems to be "Because somebody made > a mistake transcribing a mathematics paper many years ago." :-) The Python notation for anonymous function is almost a direct reference to the original notation for such functions in lambda calculus: λx.x+1 ... lambda x: x+1 I think that's an excellent hint for students to look up on this great piece of mathematical logic: https://en.wikipedia.org/wiki/Lambda_calculus and learn something about the foundations of computer science. Why the Greek letter lambda ? Who knows -- mathematicians love Greek letters, logic is λογική in Greek, ... https://en.wikipedia.org/wiki/Lambda_calculus#Origin_of_the_lambda_symbol And, of course, if you don't like anonymous functions, you're always free to give your functions names in Python ;-) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Feb 17 2021) >>> Python Projects, Coaching and Support ...https://www.egenix.com/ >>> Python Product Development ...https://consulting.egenix.com/ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 https://www.egenix.com/company/contact/ https://www.malemburg.com/ ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/CRHVZBRDAY6M2HOWGXX6REWQWTTHFFSF/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Alternate lambda syntax
On Wed, Feb 17, 2021 at 01:03:40AM +0400, Abdulla Al Kathiri wrote: > From Wikipedia: > "The term originated as an abstraction of the sequence: single, > couple/double, triple, quadruple, quintuple, sextuple, septuple, > octuple, ..., n‑tuple, …" And that's so obvious in hindsight. Thank you. -- Steve ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/OW72BO43HECV7H6EEW7PA43C3O5T6ORS/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Alternate lambda syntax
On 17/02/21 7:10 am, Steven D'Aprano wrote: Its no more "magic" than tuple, deque, iterator, coroutine, ordinal, modulus, etc, not to mention those ordinary English words with specialised jargon meanings like float, tab, zip, thread, key, promise, trampoline, tree, hash etc. Actually, I think it is -- all those words build on a pre-existing meaning in some way, and in most cases you can trace the etymology back to something the person is most likely already familiar with. Lambda, on the other hand, is a completely fresh arbitrary choice. I agree that the technical meaning has to be taught in any case, though. -- Greg ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/WBTJLJ4NSARXBPJM4VYSJRVFIRT2DQHW/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Alternate lambda syntax
On 17/02/21 7:10 am, Steven D'Aprano wrote: "It's Greek letter, like pi that you may remember from maths class. In some technical computer science, the Greek L, lambda, is used as the symbol for functions." The most accurate answer seems to be "Because somebody made a mistake transcribing a mathematics paper many years ago." :-) -- Greg ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/UW6436X65TGMC4D5ROIW4MH7GYUJQS5L/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Alternate lambda syntax
From Wikipedia: "The term originated as an abstraction of the sequence: single, couple/double, triple, quadruple, quintuple, sextuple, septuple, octuple, ..., n‑tuple, …" > On 16 Feb 2021, at 10:10 PM, Steven D'Aprano wrote: > > And I still > don't know where the word comes from in the first place. Given that it > is used in maths, probably Latin, Greek or Arabic. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/2XJSJI5D3VFVDOWAGYANBPD7EFTZ62MD/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Alternate lambda syntax
On Tue, Feb 16, 2021 at 11:38:33AM -0500, Ned Batchelder wrote: > "lambda" is unnecessarily obscure. > > Beginner: "why is it called lambda?" > > Teacher: "Don't worry about it, just use it to define a function" That's a bad answer. A better answer that is more appropriate for nearly everyone is "It's Greek letter, like pi that you may remember from maths class. In some technical computer science, the Greek L, lambda, is used as the symbol for functions." Two sentences, a few seconds to say. At this point the student almost certainly will be either satisfied with the answer, and have learned something new, or will be satisfied with the fact that there is an answer, and promptly forget it because they didn't really care, they just want to know that there is a reason. And for that perhaps one in fifty who go on to ask "Why lambda?", the answer is "They had to choose some letter, and lambda was the one they picked." I don't understand people who are unwilling to explain things. It makes me sad. > I'm not taking a side on whether to change Python, but let's please not > lose sight of just how opaque the word "lambda" is. People who know the > background of lambda can easily understand using a different word. > People who don't know the background are presented with a "magic word" > with no meaning. That's not good UI. You know the approximately 7.4 billion people in the world who aren't native English speakers? And the approximately 5 billion people who speak no English at all? They just said "Welcome to our world!" Honestly, I think this argument about lambda being a magic word is both privileged and silly. Its no more "magic" than tuple, deque, iterator, coroutine, ordinal, modulus, etc, not to mention those ordinary English words with specialised jargon meanings like float, tab, zip, thread, key, promise, trampoline, tree, hash etc. It's just a word. Every single word that we know had "no meaning" to us at some point. None of us were born knowing what "raise" or "hex" means. There is a *ton* of jargon to learn on the way to becoming a decent programmer, I don't know why lambda is singled out for so much hate. Personally I had much more difficulty learning "tuple", or "turple" as I insisted on spelling it for about the first five years. And I still don't know where the word comes from in the first place. Given that it is used in maths, probably Latin, Greek or Arabic. -- Steve ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XQXLIZTJ33MXNJ5KZB6OBLVFQQH25XIM/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Alternate lambda syntax
On Tue, 16 Feb 2021 at 16:40, Ned Batchelder wrote: > > "lambda" is unnecessarily obscure. > > Beginner: "why is it called lambda?" > > Teacher: "Don't worry about it, just use it to define a function" > > I'm not taking a side on whether to change Python, but let's please not > lose sight of just how opaque the word "lambda" is. People who know the > background of lambda can easily understand using a different word. > People who don't know the background are presented with a "magic word" > with no meaning. That's not good UI. Agreed. When lambda was introduced, "anonymous functions" were not as common in programming, and the most obvious example of their usage was in lisp, where "lambda" was the accepted term. Since then, lisp has not gained much additional popularity, but anonymous functions have appeared in a number of mainstream languages. The syntax is typically some form of "a, b -> a+b" style, and *never* uses the term "lambda". So someone coming to Python with any familiarity with other languages will now find Python's form atypical and obscure. People coming with no experience of other languages will need to have a history lesson to understand why the term is "lambda" rather than "something more obvious". People can, and will, learn Python's syntax. This isn't a major disaster. But if this were a new feature, we'd not be having this discussion, and "lambda" wouldn't even be a consideration. I'm also not taking a side on whether a change is worth the disruption. Personally, I prefer the arrow syntax, but we're not making a decision in a vacuum here. Someone has to make a case (probably in a PEP) if this is going to change, and the trade-offs should be clarified there. Paul ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/M25C6O55JCYLFOUW7DPPFGAETVOGN6R5/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Alternate lambda syntax
"lambda" is unnecessarily obscure. Beginner: "why is it called lambda?" Teacher: "Don't worry about it, just use it to define a function" I'm not taking a side on whether to change Python, but let's please not lose sight of just how opaque the word "lambda" is. People who know the background of lambda can easily understand using a different word. People who don't know the background are presented with a "magic word" with no meaning. That's not good UI. --Ned. On 2/14/21 11:39 AM, Paul Sokolovsky wrote: Hello, On Sat, 13 Feb 2021 14:33:43 -0800 Christopher Barker wrote: There seems to be a frequent objection to the word "lambda" -- personally, I found it cryptic, but it's not hard to remember, and it IS easy to look up. There seems to be a bit too many posts downputting the "lambda" keyword, and nobody went for its defense, so let me do that. The "lambda" is perhaps the greatest thing in Python after... after... well, maybe it's the single greatest thing in Python. As someone coming to Python from LISP (many years ago), I really appreciate it, and always considered Python to be "a LISP for real world". So, it's of great utility to people familiar with functional programming, but even of more utility to novices who are not yet - thanks to it, by looking it up, they can get acquainted with the wonderful world of functional programming and history of programming languages. Lambda is a sacred keyword, please don't touch! ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/DVCY2WHPO3N5R4I325ETOZUVBBZOJS7I/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Arrow functions polyfill
On Tue, Feb 16, 2021 at 04:43:11PM +0100, Sven R. Kunze wrote: > >>> obj = lambda: 0 > > to define an anomyous object without the need to define a class first > (speaking of brevity). > > > "Why?", you may ask. The reason is that: > > >>> obj = object() > > does not create an instance of obj that can be used to add some > attributes later on. >>> from types import SimpleNamespace >>> obj = SimpleNamespace() >>> obj.spam = 1 >>> obj namespace(spam=1) Gives you a nice repr so when you are debugging you can actually see what the object is. -- Steve ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/YVTKNC6GEJS2RE2ZCU4YRQ7NVG4AFILY/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Arrow functions polyfill
On 15.02.21 22:42, Greg Ewing wrote: On 16/02/21 6:29 am, Guido van Rossum wrote: I can sympathize with trying to get a replacement for lambda, because many other languages have jumped on the arrow bandwagon, and few Python first-time programmers have enough of a CS background to recognize the significance of the word lambda. I think there's also just a desire for brevity. In the situations where it's appropriate to use a lambda, you want something very compact, and "lambda" is a rather long and unwieldy thing to have stuck in there. I hope I am not saying something outrageous now but we used >>> obj = lambda: 0 to define an anomyous object without the need to define a class first (speaking of brevity). "Why?", you may ask. The reason is that: >>> obj = object() does not create an instance of obj that can be used to add some attributes later on. So, my conclusion is, if "()->0" replaces "lambda:0", this very important use-case should still be possible. :-P Or make "object()" mutable. :-D [...] I'm not arguing for or against anything here, just exploring possible reasons why the idea of lambda-replacement comes up so often. I agree the most obvious reason would be that it looks different than in other languages (same for me when I discovered it like 10 years ago). But as Guido said it's fixed already and I don't think it adds much to the language IMHO. Maybe, I'm too old to see the benefit of changing it. I like named functions because, well, they have a name attached to them and that makes bug-fixing, debugging, logging, etc. much easier. Best, Sven ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/YX7F2WM6QFWCKDRCSZHXAZ5HJ3LOSIMA/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Arrow functions polyfill
Steven D'Aprano writes: > lambda a, b, c: a+b*c > (a, b, c) -> a+b*c Of course, the mathematicians' spelling would be (a, b, c) |-> a+b*c (Don't bother throwing things, I'm already a 5km down the road.) ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/2ZAITS4HNVADQFDTYRYPRXT5R2MTXWGH/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Conditional with statements
On 16/02/2021 05:45, Christopher Barker wrote: Still OT ... But I do think you need to consider not just your editor -- if anyone else is going to read your code. They're not (in any universe I can imagine). Exactly -- the most important thing about style is that it be consistent within a project's development team -- if that's just you, then you're all set. you also have other checks in there, so those would have to be moved into the functions in the dict, maybe with wrappers (or not -- depends on where you store some of that state data. Exactly. Some wasted effort to turn a simple, contiguous, transparent chunk of code into something more complicated, spread out and harder to understand. As i said -- depends on the rest of your code. It could make it less spread out and easier to understand :-) I don't understand how it could be less spread out when it starts as a single contiguous piece of code. Perhaps I wasn't clear but when I said "spread out" I meant multiple bits of code in different places in the program. IOW how many parts it consists of (minimum = 1 = not spread out at all). For the most part using a dict to switch makes the most sense if the same pattern will be used with multiple "switch dicts". Again, turning simple straightforward into more complicated code. (I'm quite capable of writing tricks like that *when I think they're appropriate*; I've done it many times.) I'm not sure I'd call it "tricks" -- but anyway, I've found that big nested ifelses are rarely the cleanest solution -- but not never. - Chris B. -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/WEHFV5TR5UZMV2QZE7AASFWDCJSAPHSE/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Alternate lambda syntax
On 15/02/2021 19:47, Mike Miller wrote: On 2021-02-13 14:33, Christopher Barker wrote: On Fri, Feb 12, 2021 at 1:00 AM Brendan Barnwell mailto:brenb...@brenbarn.net>> wrote: The only thing that would be better than lambda is a less confusing keyword. There seems to be a frequent objection to the word "lambda" -- personally, I found it cryptic, but it's not hard to remember, and it IS easy to look up. But if you don't like that word, why not "def"? Every place I've tried to use "def" where "lambda" is legal, it's a syntax error. So we could use the same word. Would that be less confusing? Agreed. It isn't too important at this point, but I'd also skip the punctuation and add an expression version of def: def named_function(x, y): return x * y anonymous_function = def x, y: x * y That seems sensible, if there is no syntactical ambiguity. Parentheses on the parameter list could be allowed as well. Yes please! That is a feature of Python 2 that I miss in Python 3. Javascript has (too much) flexibility in this area, but I wouldn't mind Python loosening slightly to use the keyword it probably should have in the beginning. -Mike ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/YHVQIVD6AZFANODLEBMVLNOTGWKK6GZ3/ Code of Conduct: http://python.org/psf/codeofconduct/ ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/2LF7NSNNEYFTH5CTNE7BUDCUNO5T6QCI/ Code of Conduct: http://python.org/psf/codeofconduct/