3 ms·
Python also has lambda syntax, therefore closures are quite easy to do. Example: items.select {|e| e.isFoo} It's arguably more terse and superior to javascrip
by justncase80 15y ago
Python also has lambda syntax, therefore closures are quite easy to do. Example:
items.select {|e| e.isFoo}
It's arguably more terse and superior to javascript in that particular feature as well.
- steve-howard 15y agoThat's Ruby, if I'm not mistaken. In Python you'd do filter(lambda e: e.isFoo, items)
- andreasvc 15y agoIt's more Pythonic to write [e for e in items if e.isFoo]
- icebraining 15y agoBesides being Ruby, that's not a closure, just an anonymous block/function. A closure closes over some non-local variables, while that block doesn't.
- deleted 15y ago[deleted]
- whateverer 15y agoBut... Uhhhh... that was Ruby you just showed there. And Python's anonymous functions are deliberately crippled because the Grand BDFL dislikes functional programming (often tried to be sneaked around by those dastardly Schemers, curse them!).
- justncase80 15y agoYup, you're all right, I copied the wrong snippet it seems. I don't know how that happened. And it's also true that that lambda doesn't have a closure (double fail) but in my experience a lambda usually implies the possibility of a closure. Is that a bad assumption? Thanks for the corrections.