Re:Haskell language features and standard libraries in pure ...
by amelius on Tuesday September 22, 2020 @02:21PM
(#24558057)
Sadly, creating decent-looking multi-line lambda functions is not really possible in Python, afaik.
[ Parent
| on HN ]
Re:Haskell language features and standard libraries in pure ...
by klipt on Tuesday September 22, 2020 @02:31PM
(#24558153)
Why does it need to be anonymous if it's multi line? You can just do a local 'def'.
Re:Haskell language features and standard libraries in pure ...
by rowanG077 on Tuesday September 22, 2020 @02:32PM
(#24558162)
You cannot use def within function call parenthesis.
Re:Haskell language features and standard libraries in pure ...
by OJFord on Tuesday September 22, 2020 @02:41PM
(#24558251)
But you can pass a def'd function within function call parentheses.
Re:Haskell language features and standard libraries in pure ...
by gnulinux on Tuesday September 22, 2020 @03:01PM
(#24558464)
I would still prefer having a multiline lambda. We have this:
def f(x):
y = foo(x)
z = bar(y)
// ...
return x
some_obj.do_later(t, f, a, b, c)
I would prefer: some_obj.do_later(t, lambda x: {
y = foo(x)
z = bar(y)
// ...
return x
}, a, b, c)
Maybe ( instead of {? I'm not sure that's possible to parse. Regardless, something like this would be good.
Re:Haskell language features and standard libraries in pure ...
by OJFord on Tuesday September 22, 2020 @03:40PM
(#24558903)
Yes, I have wanted that before, and it could use existing valid syntax:
some_obj.do_later(t, (lambda x:
# (presently only a single non-comment line would be valid)
x
), a, b, c)
Re:Haskell language features and standard libraries in pure ...
by cwhy on Wednesday September 23, 2020 @12:53AM
(#24563108)
In Python people are encouraged to follow styles for code as a communication tool between developers. If you just really want your code to "look nice" you can have things like this:
def begin(*args):
return args[-1]
begin(
func := lambda x, y: begin(
z := int(input()),
x + y + z
),
func(1, 2)
)
from `https://news.ycombinator.com/item?id=23346534`
Re:Haskell language features and standard libraries in pure ...
by contravariant on Tuesday September 22, 2020 @07:28PM
(#24561238)
I suppose lambdas are already a bit weird for ending with a : without starting a new code block.
Good luck fixing that though.
Re:Haskell language features and standard libraries in pure ...
by rowanG077 on Tuesday September 22, 2020 @02:57PM
(#24558431)
Of course you can. But it's very different. A lambda is guaranteed to only be used by the function it's passed to. A local def pollutes the scope with an additional identifier that leads to less code clarity.