3 ms·
Allowing to elide the add42 from "def add42(x): x+42" makes the difference between encouraging FP or not? I've actually started wishing for the opposite change
by fulafel 8y ago
Allowing to elide the add42 from "def add42(x): x+42" makes the difference between encouraging FP or not?
I've actually started wishing for the opposite change in my use of Clojure. There, it is currently optional to supply a name for the fn form. Always supplying the name, like in "(fn add-42 [x] (+ x 42))", would make stack traces more readable and the named function object would be easy to identify when it appeared in the REPL / pretty-printed data structures.
- darkpuma 8y ago> "Allowing to elide the add42 from "def add42(x): x+42" makes the difference between encouraging FP or not?" Not being able to define a two-line function in the place where it's used because you have to give it a name discourages FP in a way many other modern languages do not.
- stormking 8y agoNot really, since Python can nest functions: def something(x): def myfunc(y, z): ... return result reduce(myfunc, x) So the difference is like having to write x = some_very_complex_expression_that_can_get_quite_long some_function(x) instead of some_function(some_very_complex_expression_that_can_get_quite_long) In many cases this may make code even more readable. I'm not saying that Python's lambdas are perfect as they are or that multi-line lambdas would be a bad thing. I'm just saying it's not as bad as you paint it.