Re:"Real" anonymous functions for Python
by ElevenLathe on Friday March 29, 2024 @10:10AM
(#39864318)
The major killer feature of scheme-style lambdas is that you don't have to name them. Naming stuff is hard, and you usually get it wrong. If the thing you want to do is a couple lines of code, and you can just drop it in as a lambda and not have to think of a meaningful name, it's easier to keep flow-state. If things expand to the point where glancing at the code doesn't tell you what the function does, that is the time to break it out into a named function.
[ Parent
| on HN ]
Just call it foo. Not a problem.
Re:"Real" anonymous functions for Python
by knightoffaith on Sunday March 31, 2024 @01:58PM
(#39886437)
You can still do anything you want with just Python lambdas technically speaking right? Like, Python lambdas can express any lambda calculus expression, so as long as you're not writing something with side effects, you can use an arbitrarily complex Python lambda. Though I guess the resulting code wouldn't exactly be Pythonic.
Re:"Real" anonymous functions for Python
by powersnail on Sunday March 31, 2024 @02:44PM
(#39886866)
Depends on what you mean by "technically".
Computationally, python lambda is fully capable of whatever a regular python function can do, including side-effects, (you can call foo.set_bar()).
The limit is syntactical: a lambda has to be one single expression. So, no assignment statement, no multiple lines, etc.
Re:"Real" anonymous functions for Python
by constantcrying on Sunday March 31, 2024 @02:39PM
(#39886809)
Language design is really about what you could do, but about how to efficiently express certain things.
> Language design is really about what you could do, but about how to efficiently express certain things.
That's missing a "not", right (probably after "really")?
Re:"Real" anonymous functions for Python
by ElevenLathe on Wednesday April 03, 2024 @11:19AM
(#39918611)
Not the person you're replying to, but I assume they meant "rarely" instead of "really". I make this typo all the time myself!