4 ms·
> foo.on_click(lambda: x += 1) Mutation in lambdas is not compatible with your complaint about "inadequate support for high-level functional programming", as i
by amyjess 10y ago
> foo.on_click(lambda: x += 1)
Mutation in lambdas is not compatible with your complaint about "inadequate support for high-level functional programming", as it goes against the principles of FP.
You can't do that in Haskell either, and any FP purist would blanch at a statement like that.
- darkf 10y ago>You can't do that in Haskell either, and any FP purist would blanch at a statement like that. Obviously you've never met State and/or lens then. Yes, you can do it -- and no, I never said it should follow pure FP principles.
- lmm 10y agoBut if you write a State equivalent of "x += 1" in Python then you can use it in a lambda too.
- codygman 10y ago> You can't do that in Haskell either, and any FP purist What about us FP pragmatists? Also in some domains I'd argue being a FP purist is the most pragmatic option.
- kazinator 10y agoAre you saying that a non-mutating variant of the above works? For instance: foo.on_click(lambda:x func(x, whatever))
- dragonwriter 10y agoyeah, except that the syntax is lambda x: func(x, whatever) In fact, if x is an object that stores a mutable numeric cell, you could even do a mutating: lambda x: x.add(1) Mutation isn't prohibited in Python lambdas, statements (including assignments, which are statements rather than expressions in Python), however, are.