On 18.08.2013 16:51, Hussein B. wrote:
Would you please help me transforming this imperative code into
functional one?
The code is a typical snippet in imperative style. A lot of mutations
that I don't even know how to start morphing it to Clojure.
class Container {
MapString,
On 19.08.2013 20:27, Timo Mihaljov wrote:
This example may be to artificial to be translated into Clojure. What
use is it to store strings in a tree keyed by the string's characters?
If you know the path to the string, you already know the string itself,
and you don't need the tree at all!
Hi!
Would you please help me transforming this imperative code into functional
one?
The code is a typical snippet in imperative style. A lot of mutations that
I don't even know how to start morphing it to Clojure.
class Container {
MapString, Container children;
String letter;
Can you explain what the code is supposed to do in English? Java is a
little hard to read. :-)
Are you doing Huffman coding or similar?
On 18 August 2013 16:51, Hussein B. hubaghd...@gmail.com wrote:
Hi!
Would you please help me transforming this imperative code into functional
one?
The
It might be Huffman coding but I don't know Hoffman coding in depth, so I
can't be precise. :)
But any way, it is a snippet written in an imperative style that I'm trying
to transfer into a functional one.
The amount of mutation and the if statements are blocking me from doing it
in Clojure.
This is close, though it only permits values at leaves and stores the
values in the reverse order. Depending on what you need, this might be
sufficient:
(defn insert [container letters value]
(update-in container letters #(conj % value)))
e.g. (- {} (insert foo 3) (insert foo 4) (insert bar
Here's a version that allows values to be anywhere in the tree:
(defn insert [[container values] [letter letters] value]
(if letter
[(update-in container [letter] #(insert % letters value)) values]
[container (conj values value)]))
e.g. (- [{} []] (insert foo 4) (insert f 5) (insert