4 ms·
Python's comprehensions were lifted from Haskell, and its map and filter functions also operate on iterables. They can't be purely functional because of the sur
by duckerude 8y ago
Python's comprehensions were lifted from Haskell, and its map and filter functions also operate on iterables. They can't be purely functional because of the surrounding language, but they do follow a functional style.
(expr for item in iterable if cond) is more or less another way to spell map(lambda item: expr, filter(lambda item: cond, iterable)), except readable.
You could define "functional programming" to absolutely require referential transparency, but that's not what the rest of the thread is doing.
- kthielen 8y agoI don't mean to be pedantic but IIRC Python's comprehensions actually came from the SETL language. Obviously it's ultimately the same thing either way, but that's the lineage (SETL -> ABC -> Python). https://en.wikipedia.org/wiki/SETL https://en.wikipedia.org/wiki/SETL
- duckerude 8y agoI didn't know about SETL, that's interesting. https://docs.python.org/3/howto/functional.html#generator-expressions-and-list-comprehensions https://docs.python.org/3/howto/functional.html#generator-ex... claims Python borrowed them from Haskell, but the ABC link seems more likely.
- zephyrfalcon 8y agoABC didn't have list comprehensions though, in spite of being influenced by SETL. As I recall, Python did get them from Haskell, which in turn got them from Miranda, which got them from KRC. Before that it gets fuzzy, but it's likely that SETL was eventually at the root of it.