|
|
|
|
|
by saghm
2212 days ago
|
|
I agree with you that having more than a single expression in lambdas would be super nice. That being said, I don't think it's necessarily stateful to allow more than a single expression! If you don't reassign any variables, then it's equivalent to a single expression. For instance, something like this (using made up syntax for extended lambdas) isn't stateful: lambda i:
square = i * i
if i < 0:
return -1 * square
else:
return square
A decent heuristic for whether an algorithm is stateful might be to check if you can map it pretty easily to something like Haskell. In this case, it's not hard to do at all: \i ->
let square = i * i in
if x < 0 then -1 * x else x
Of course, it might be more natural for some programmers to write the Python code in a stateful way like this: lambda i:
square = i * i
if i < 0:
square *= -1
return square
|
|