Roman Numerals in Clojure

I saw this post on Roman Numerals in Clojure:

http://www.jayway.com/2012/08/04/a-decimal-to-roman-numeral-converter-in-just…

This is the sort of little programming problem that can stop useful work dead in its tracks. Here’s my shot at the problem. I think it reads better in that the recursion just deals with the numbers and the Roman numeral strings are mapped latter. It’s also a bit more efficient in the way it tests against the Roman “bases” (as I call them). There’s no need to retest against a high base once your interim value has gone below that mark. In any case, my version is quite a bit faster than the other solution in my micro-benchmarks.

Advertisements

Reducers at EuroClojure

http://thegeez.net/2012/06/12/euroclojure_reducers.html?utm_source=dlvr.it&am…

Fold will try to do the computation in parallel using fork/join, when the input collection that is asked to apply the reducer to itself supports this and when the reducer supports this. The check for support is done through protocols: for the datastructures: PersistentVector extends CollFold, for the reducers: r/map is defined as a folder, while r/take-while is defined as a reducer (and does not support fold, because partitioning does not make sense for this computation). When parallel fold is not supported, then fold will just do a reduce. See the implementation for details: reducers.clj

A common approach for parallel processing is to use map+reduce. The work is divided into partitions and map is applied to each partition and the intermediate results are combined with reduce. In fold the approach is reduce+combine. The work on the smallest partition is done with a reduce rather than with map. Compare the two approaches by trying to express filter in map+reduce versus reduce+combine. It appeals to the functional programming sensibilities that reduce is a better fit for most operations than map.