Open KnorrFG opened 5 years ago
random internet passerby here. I've considered hacking the cpython source code to add a more ergonomic lambda syntax. It couldn't be too hard to substitute a different keyword, say, fn
, but I'm partial personally to javascript arrow notation ((x) => x * 2
). apologies for hijacking thread (it's a subject near to my heart), but any thoughts on feasibility of this would be welcome.
random internet passerby here. I've considered hacking the cpython source code to add a more ergonomic lambda syntax. It couldn't be too hard to substitute a different keyword, say,
fn
, but I'm partial personally to javascript arrow notation ((x) => x * 2
). apologies for hijacking thread (it's a subject near to my heart), but any thoughts on feasibility of this would be welcome.
I'd love that, both options, but you'd have to write a PEP for that, and that would probably be discussed for a year and then be rejected ^^
the official process has already been tried and, as you expected, failed. I had in mind more of a rogue, pirate distribution. Perhaps we can bring back eager map
(et al), reduce
in the global namespace, and other things Guido killed over the years :).
@jstrong-tios If you ever get around to it, I wanted to comment that one of the best things about those Javascript arrow functions you brought up is that they make writing curried functions very ergonomic: let add = x => y => x + y
. I hope whatever you do in your fork of Python is similarly nice for both regular and curried functions.
@KnorrFG since you said you couldn't find it anymore: placeholder
is the best library I know of that does what you're talking about (lambda shorthand with _
).
@KnorrFG oh, also, placeholder
has a workaround for edge cases like len(_)
: from placeholder import F
and then F(len)
.
So for example instead of last_index = len(_) - 1
you would do last_index = F(len) - 1
.
It's debatable if this is too unclear to be better, but it's there as an option.
Hey, I love toolz, but the one thin I've been missing is a possibility to create lambdas in a less verbose way. At some point I had installed a library (which I can't seem to find anymore) that created lambdas through the use of
_
. Eg_ == x
was translated to:lambda x: x == 3
but it had it's limits as something likelen(_)
would not work.I wrote a function that takes a string, replaces percent signs by arguments and evals it:
Trying it out:
I found this would fit one of my favorite libraries perfectly, what do you think about this?