2 ms·
Really? There's only two bits of punctuation there, and they don't take much to explain: #(...) is an anonymous function; % is the argument to that function. (I
by kenko 14y ago
Really? There's only two bits of punctuation there, and they don't take much to explain: #(...) is an anonymous function; % is the argument to that function. (I'm not counting > because ... it's just the greater-than sign.)
The Haskell version doesn't actually do the same thing. The Haskell returns [76, 82, 88, 90]; the Clojure returns ((49 58) (76 82 88 90))---it groups the input according to the result of the function, it doesn't just filter it.
- Chris_Newton 14y agoIt’s not an ideal example of partition-by anyway, because this particular input has all the values where the predicate returns true together. As you have shown, the result in this case is just to divide the list into the values that match the predicate and those that don’t. This is actually what the “partition” function does in some languages, including Haskell and Scala. However, in general, partition-by in Clojure does more than that and is more like a kind of split algorithm, which this example didn’t demonstrate. In any case, my point here was about syntax, so I used a standard and easily recognisable function in the other languages instead of getting bogged down in trying to reproduce the exact same behaviour. Apologies if this wasn’t clear.