3 ms·
I'm confused by the last example. There are no elements greater than 5 in the list (1 2 3 4). Also, I'm not sure why they used takewhile instead of filter in t
by iamcurious 11y ago
I'm confused by the last example. There are no elements greater than 5 in the list (1 2 3 4).
Also, I'm not sure why they used takewhile instead of filter in the last haskell part.
- Xophmeister 11y agoI assumed it to be a typo; i.e., it should say "less than". `takeWhile` is different to `filter` in that is returns the input list until some element matches the predicate, whereas `filter` returns all elements that match the predicate. For example, if the predicate is `(< 5)` and the input was `[9, 2, 3, 6]`, then `takeWhile` would return an empty list, but `filter` would return `[2, 3]`.
- gkya 11y agoHe should have used a better input, though, maybe 1, 2, 3 ,4 ,5. With the given input it's a bit confusing, it's equivalent to filter . even [1..4]. Also, the Lisp loop should have been checking for (>= i 5), to be equivalent to the Haskell example.
- iamcurious 11y agoYes, but I expected to see (filter even . filter (< 5)) [1..4] given the specification and the lisp counterpart. I do not fully understand the lisp code, so I can't be sure what is a typo and what is an erroneous assumption from my part.