Re:Typesafe raises $14M to commercialize Scala
by kenko on Wednesday August 22, 2012 @12:38PM
(#4418220)
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.
Re:Typesafe raises $14M to commercialize Scala
by Chris_Newton on Wednesday August 22, 2012 @01:18PM
(#4418410)
It’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.
Re:Typesafe raises $14M to commercialize Scala
by Dn_Ab on Wednesday August 22, 2012 @12:23PM
(#4418150)
I know this is a discussion on syntax but I can't help pointing out that the semantics of paritition-by and filter are very different.
Re:Typesafe raises $14M to commercialize Scala
by Chris_Newton on Wednesday August 22, 2012 @12:58PM
(#4418311)
True enough, but I figured filter was widely known and partition-by was perhaps a little esoteric. The syntactic argument would be exactly the same if you used an equivalent of partition-by in the other languages.
Re:Typesafe raises $14M to commercialize Scala
by wtetzner on Wednesday August 22, 2012 @10:52AM
(#4417610)
>(partition-by #(> % 60) [49 58 76 82 88 90])
Yeah, a less noisy way to do it in Clojure would be
(partition-by (partial < 60) [49 58 76 82 88 90])
For comparison, here’s a Haskell version, which in this case has a more intuitive syntax, IMHO:
And here’s a version in Scala, with a more explicit function value: