News for hackers. Stuff that matters.
Re:Guido was right, there should be no lambda in Python (2018) by shrimpx on Tuesday September 27, 2022 @07:43PM (#33002609)
The author makes a bunch of tenuous assumptions; that lambda calculus is all about currying; and that the “lambda” keyword brings lambda calculus to Python; that lambda is undesirable because Python doesn’t have nice currying syntax.

Anyway I think Guido hates lambda because it feels like an appendage in Python, due to list comprehensions and due to expression-only bodies, restriction which was put in place probably because passing multi-line nameless functions as arguments is awkward in a whitespace-sensitive language/it just didn’t feel Pythonic to Guido to be passing large inline functions to functions.

Re:Guido was right, there should be no lambda in Python (2018) by dreamcompiler on Tuesday September 27, 2022 @09:54PM (#33003427)
> The author makes a bunch of tenuous assumptions; that lambda calculus is all about currying

My first thought exactly. Lisp is based on lambda calculus and it doesn't do automatic currying. Multiline lambdas require block delimiters more sophisticated than whitespace; hence they don't work in Python. It's no more complicated than that.

Re:Guido was right, there should be no lambda in Python (2018) by kazinator on Wednesday September 28, 2022 @02:34AM (#33004868)
What Lisp doesn't do is partial application: returning a function of N-M arguments when you only apply M arguments to one that needs N.

Languages which do that have issues representing very useful software engineering tools: optional arguments, variadic arguments and keyword arguments.

Currying is related to partial application; it refers to a technique for representing multivariate functions using only functions of one argument.

E.g. to obtain some f(x, y, z) we instead make it f(x)(y)(z), where f is a one-argument function applied to (x). That yields an anonymous one-argument function that is applied to (y), and that again yields a one-argument function applied to (z), which finally calculates f(x, y, z).

Whereas partial application is this: we already have a bona fide three-argument f(x, y, z), and the ability to call it with all three arguments at once. But for some reason, we call it as f(x)(y)(z). Now f needs 3 arguments but is called with just one, (x). So an anonymous two-argument function is produced which, if given two arguments will combine those with the one that was given and call f. Alas, that function is given only one argument, so it returns another one-argument function. When that one is given an argument, it all unwraps, and f ends up being called. These anonymous functions are understood to be produced because our notation is understood to have implicit partial application semantics. Under currying, things aren't implicit; f(x) is written as a one-argument function, which will have a lambda term in it. There is nothing to be implicit about in terms of application: all functions have one argument.

Re:Guido was right, there should be no lambda in Python (2018) by dreamcompiler on Wednesday September 28, 2022 @09:49PM (#33015454)
Thanks for the clarification. I'm guilty of saying things like "Haskell does automatic currying" when in fact it does automatic partial application. But then again I don't actually know what goes on under the sheets in Haskell. It might in fact convert every multi-argument function to a nested single-argument curry-like lambda form internally, whether it needs to or not. I expect that would be inefficient (because it would cons up a lot of unnecessary functions), but it's possible. Does Haskell only do partial application when it actually needs to, or does it do single-argument curry-ish partial application of every function regardless?
Re:Guido was right, there should be no lambda in Python (2018) by shrimpx on Thursday September 29, 2022 @02:37AM (#33017205)
Btw I’m not an expert but I believe Haskell treats all functions as unary, but they’re translated to N-ary in an optimizing compiler.
Re:Guido was right, there should be no lambda in Python (2018) by Ferret7446 on Saturday October 01, 2022 @01:15AM (#33044090)
That sounds like semantic wordplay. Functionally, how is currying and partial application different? Given two otherwise identical languages which use either currying or partial application, both languages would run every single program exactly the same way.
Re:Guido was right, there should be no lambda in Python (2018) by shrimpx on Tuesday September 27, 2022 @10:23PM (#33003581)
I think if you really tried you could make it work but there are a lot of ugly and unique tradeoffs to work through. Something like this could work:

  foo((lambda x, y:
         for i in range(x):
           y += i
         return y),
      20
  )
Re:Guido was right, there should be no lambda in Python (2018) by kazinator on Wednesday September 28, 2022 @03:13AM (#33005088)
It could work like this:

   foo (lambda x, y::, 20)    # :: means body of lambda follows
     ::                       # optional, if there is only one lambda and line has no argument lines
       for i in range (x):
         y += i
       return y
The lambda bodies immediately follow the line. If the line has arguments, those follow the lambdas:

   if foo(lambda x::, list) < bar(lambda y::, list):
     ::                  # lambda x
       return x + x
     ::                  # lambda y
       return 2 * y
     return list         # then statement of if
Re:Guido was right, there should be no lambda in Python (2018) by kazinator on Wednesday September 28, 2022 @01:00PM (#33010305)
The def keyword followed by a colon could be used as the marker for the continuation material that supplies the multi-line lambada bodies.

Perhaps the double colon would be unnecessary: just make the expression optional, and if it's missing then there has to be an "outboard" body.

   if foo(lambda x:, list) < bar(lambda y:, list):
     def:                # lambda x
       return x + x
     def:                # lambda y
       return 2 * y
     return list         # then statement of if
Re:Guido was right, there should be no lambda in Python (2018) by pharmakom on Wednesday September 28, 2022 @02:18AM (#33004782)
F# manages it. I think this really holds Python back as a more powerful scripting language.
Re:Guido was right, there should be no lambda in Python (2018) by p1necone on Tuesday September 27, 2022 @08:44PM (#33003012)
Imo the whole whitespace sensitivity thing was a mistake to begin with. It makes code harder to read, harder to write and harder to parse with only the benefit of being a little easier to understand to absolute beginners (and I'm not even sure about that last one).
Re:Guido was right, there should be no lambda in Python (2018) by Entinel on Tuesday September 27, 2022 @08:51PM (#33003068)
I am very much not a beginner and I don't find whitespace sensitive languages hard to read. I don't find Lisp hard to read either. Or C-style languages for that matter. The sheer passion people have towards whitespace vs brackets vs parenthesis makes me question their sanity.
Re:Guido was right, there should be no lambda in Python (2018) by TheRealPomax on Tuesday September 27, 2022 @08:56PM (#33003095)
Congrats: you are an outlier. That's pretty cool, and it means you can read a lot of code quite easily, which I'm sure lets you be more productive than most, but you are not like most other people.
Re:Guido was right, there should be no lambda in Python (2018) by kjeetgill on Tuesday September 27, 2022 @09:19PM (#33003231)
I think this is one of those silent majority situations.

Almost all programmers can read a C-like language because well, that covers like 95% of languages by use. You have C/C++/Java/Go/JS/Kotlin/Rust/zig/C# etc.

BUT second to that in sheer use is probably Python. Almost everyone (that I know) has touched it atleast a bit whether its dev scripts, tooling, scientific work (bio, cv, etc.), robotics, mech engineers, ml/ai space etc.

Why would anyone nitpick to death tools that have so much ubiquity? Well they'd have to have a narrow focus to even consider it. The majority of algebra users never second guess +, *, ^, (), etc.

I'd say lisp is probably the hardest to get used to combine with the least frequent to cross your path. And then there's a long tail of bash/ruby styles, tcl, ocaml, etc etc.

Re:Guido was right, there should be no lambda in Python (2018) by TheRealPomax on Tuesday September 27, 2022 @09:23PM (#33003252)
I think this is a dangerous assumptions to make: the last time I looked at C was 30 years ago, you show me real C code with pointers and references and namespaces and I couldn't tell you wtf was going on if my life depended on it.

With a few weeks of study to "re"learn C and/or C++? Sure, they're just programming languages. But right off the bat? No idea what the hell is going on in real, production C code.

Re:Guido was right, there should be no lambda in Python (2018) by Entinel on Tuesday September 27, 2022 @09:35PM (#33003321)
This is my point though. People just complain about whatever syntax they aren't used to using but none of them are inherently more difficult to read.
Re:Guido was right, there should be no lambda in Python (2018) by TheRealPomax on Tuesday September 27, 2022 @09:54PM (#33003428)
None of them are inherently more difficult to _learn_ but they sure as hell are more difficult to read when everything's peppered with :: and * and &.
Re:Guido was right, there should be no lambda in Python (2018) by Entinel on Tuesday September 27, 2022 @10:22PM (#33003571)
That's a matter of opinion and one I disagree with.
Re:Guido was right, there should be no lambda in Python (2018) by thrown_22 on Tuesday September 27, 2022 @10:55PM (#33003782)
The problem of working C code isn't the syntax, it's the semantics.

Casting pointers isn't difficult to read because dereference and multiplication share *, it's difficult to understand because it's not something you do outside of C.

Re:Guido was right, there should be no lambda in Python (2018) by skywhopper on Wednesday September 28, 2022 @08:28AM (#33007115)
Maybe you don’t.
Re:Guido was right, there should be no lambda in Python (2018) by Peritract on Wednesday September 28, 2022 @04:33AM (#33005633)
In my experience, people who struggle with different syntax conventions are the outliers; if you can handle the idea of brackets generally (as we all do regularly), then you can deal with one set of conventions.

Similarly, if you can grasp the concept of a paragraph, or of bullet points, or a bunch of other things in normal text that convey meaning through whitespace, then you can deal with another.

It's only code that (some) people complain about this with. In every other context, we all know that we can work with syntax based either on brackets or spacing. Just in normal communication, all humans deal with a dizzying array of complex conventions without even thinking about it.

The reluctance to use whitespace-sensitive languages (or the other way around) is learned helplessness, rather than a widespread inadequacy.

Re:Guido was right, there should be no lambda in Python (2018) by sweezyjeezy on Tuesday September 27, 2022 @09:05PM (#33003158)
Are you sure this an outlier opinion amongst regular python users?
Re:Guido was right, there should be no lambda in Python (2018) by p1necone on Tuesday September 27, 2022 @09:08PM (#33003168)
Well no, I imagine that that group would somewhat self select for developers who are okay with reading whitespace based syntax. Someone who finds it hard to read is probably not going to become a regular user of the language unless they have to.
Re:Guido was right, there should be no lambda in Python (2018) by sweezyjeezy on Tuesday September 27, 2022 @09:20PM (#33003235)
Python is lingua franca in data science / ML, i.e. you pretty much do have to to work in the field. In my experience the people who complain about this aspect of python are those just starting out.

Dependency management would be an example of a real Python issue, not a "everyone gets used to it" one IMO.

Re:Guido was right, there should be no lambda in Python (2018) by OrderlyTiamat on Wednesday September 28, 2022 @04:12AM (#33005459)
I use python extensively, and whitespace very much is an actual issue. Not a big one, but it is annoying every once in a while e.g. when copying code. Especially as autoindenting is very much hampered in that case, because the editor can't tell what the indent is supposed to be if multiple options are valid python. Dealing with braces instead is much easier. Not a deal-breaker or major issue, but an annoyance nonetheless.
Re:Guido was right, there should be no lambda in Python (2018) by TheRealPomax on Tuesday September 27, 2022 @09:25PM (#33003265)
Why would a python programmer have any understanding of code that's full of pointers and memory addresses? You show someone who started on Python, and still uses it today, real product C code and their eyes glaze over real fast.
Re:Guido was right, there should be no lambda in Python (2018) by sweezyjeezy on Tuesday September 27, 2022 @09:29PM (#33003285)
I think you replied to the wrong person.
Re:Guido was right, there should be no lambda in Python (2018) by shrimpx on Tuesday September 27, 2022 @10:30PM (#33003628)
There's some evidence that indentation-based block delimiting is intuitive: People indent their blocks even in whitespace-insensitive languages.
Re:Guido was right, there should be no lambda in Python (2018) by majewsky on Wednesday September 28, 2022 @04:23AM (#33005543)
Indentation-based delimiting is good for reading because it provides visual structure. For writing, it's much more effective to rely on braces or parentheses instead and have the indentation be inferred by an autoformatter. For example, with braces, I can just copy-paste a statement or block of statements from somewhere else and it will have the correct semantics regardless of what indentation the source and destination end up having, and the autoformatter will immediately fix it for me.
Re:Guido was right, there should be no lambda in Python (2018) by kazinator on Wednesday September 28, 2022 @03:26PM (#33012120)
With indentation-only based delimiting, you don't know whether you're seeing the whole thing:

  def check(situation):
    if situation.under_nuclear_attack:
       situation.set_alert_level(RED)
  -------------- bottom of window -----------------
Is that the whole function? Does it forget to launch the counterstrike? Or is there more? We don't know without scrolling down.

You can change the meaning of code, without changing its whitespace sensitive diff (git diff { -w | -b }).

Re:Guido was right, there should be no lambda in Python (2018) by Izkata on Wednesday September 28, 2022 @07:43AM (#33006808)
> with only the benefit of being a little easier to understand to absolute beginners (and I'm not even sure about that last one).

This one is backwards: the benefit is forcing beginners to write well-formatted code. You would not believe the insane things people just learning can come up with, when in a C-style language where indentation doesn't matter.

Re:Guido was right, there should be no lambda in Python (2018) by thaumasiotes on Tuesday September 27, 2022 @08:48PM (#33003050)
Technically, it has the benefit that code cannot be incorrectly indented - it can't be formatted to look like the scope is one way when in reality it's another way.
Re:Guido was right, there should be no lambda in Python (2018) by kimmeld on Tuesday September 27, 2022 @08:57PM (#33003102)
Code can absolutely be incorrectly indented in python and to make matters worse it changes the functionality of the code when it is.
Re:Guido was right, there should be no lambda in Python (2018) by thaumasiotes on Wednesday September 28, 2022 @02:43AM (#33004911)
Code can be indented in a way you didn't mean for it to be. But it cannot be incorrectly indented in the sense I just described, because the indentation changes the functionality of the code. The indentation can never mislead you about the structure of the code.
Re:Guido was right, there should be no lambda in Python (2018) by Izkata on Wednesday September 28, 2022 @07:49AM (#33006844)
I've seen one case where it has, where the outdent at the end of a nested loop/loop/if was wrong: it was only 3 spaces instead of matching the 4 indent, so it looked right at a glance but wasn't. Needed to use pdb to step through it and see it do the wrong thing before that stuck out.
Re:Guido was right, there should be no lambda in Python (2018) by gleenn on Tuesday September 27, 2022 @08:46PM (#33003032)
And harder to copy-paste!
Re:Guido was right, there should be no lambda in Python (2018) by mamcx on Tuesday September 27, 2022 @10:53PM (#33003772)
Call python "harder to read" is like call rain "harder to get wet".
Re:Guido was right, there should be no lambda in Python (2018) by hsbauauvhabzb on Tuesday September 27, 2022 @09:17PM (#33003218)
I find it odd that this isn’t a configuration option in any/all language compilers. I prefer indents to braces, but understand the hate others have. Turns out AST engines could convert them relatively easily.
Re:Guido was right, there should be no lambda in Python (2018) by p1necone on Tuesday September 27, 2022 @10:05PM (#33003490)
A lot of languages do have auto formatters with opinionated defaults for this.

For go, gofmt is so opinionated that you can't even configure it, which is kinda cool because it means all go code that uses it will look the same.

There's also rustfmt for rust and prettier for JS/TS (and I assume similar for lots of other languages I'm not familiar with), both of which are configurable, which I prefer - but I can see the upsides of a one-size-fits-all code formatting tool (especially for a language like go where a reasonably constrained feature set/syntax is an explicit goal of the language).

Re:Guido was right, there should be no lambda in Python (2018) by occamrazor on Wednesday September 28, 2022 @07:24AM (#33006700)
Python has black, also not configurable.
Re:Guido was right, there should be no lambda in Python (2018) by avryhof on Wednesday September 28, 2022 @10:23AM (#33008308)
Black is pretty nice with the defaults, but it certainly is configurable these days.

It can take command line options, or it can be configured in your Poetry pyproject.toml file.

https://black.readthedocs.io/en/stable/usage_and_configurati...

Re:Guido was right, there should be no lambda in Python (2018) by Izkata on Wednesday September 28, 2022 @07:37AM (#33006781)
Er no, if you make it to the end he straight up says lambda isn't lambda calculus, shouldn't be treated as such, and is useful on its own. Basically it should be kept but named something else.