My style of programming is mostly using callback with anonymous function. This restriction prevents me to using Python in serious projects.
My style of programming is mostly using callback with anonymous function. This restriction prevents me to using Python in serious projects.
https://coconut.readthedocs.io/en/master/DOCS.html#statement...
I appreciate that won't work well for all use cases, but it'd eliminate a lot of the pain with the current lambda implementation.
For whatever reason, the Python community declared multiline lambdas as non-pythonic and this project aims to remain pythonic, so they went with semicolons instead.
I'm not a Python developer myself, but if that was the only thing holding you back, then perhaps that reason is now slightly reduced?
Assuming that Python’s support for nested functions carries over to Coconut, it seems like a reasonably-complete feature set.
L |> map$(def (x) -> (
y = 1/x;
y*(1 - y)
))
You can also make multiline python lambdas by using brackets. That is if you can fit your code into an expression.If a function is used 2 times, 3 times, ... sure, go for it. If it's just a one-time use, please don't make a separate function.
def precise_multiples_first(max_val, divisor):
print(f"Using {max_val=}")
def sort_key(val):
if val % divisor == 0:
return 0, val
else:
return 1, val
return sorted(range(max_val), key=sort_key)
vs def precise_multiples_first(range_max, divisor):
print(f"Using {max_val=}")
return sorted(range(max_val), key=lambda val: (
if val % divisor == 0:
return 0, val
else:
return 1, val
))
(Yes I know I could've squeezed that function onto one line e.g. using ternary operator, but it was just a quick example.)