Moses
unread,May 25, 2009, 11:14:24 PM5/25/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Clojure Study Group Washington DC
I've been trying to write a trie implementation over the last few
days, I'm very new to the language, so progress has thus far been very
slow. Here's what I have so far:
;; Adds a word to an existing trie
(defn process-word
"This function recursively processes
the characters in a word"
[trie word]
(if (empty? word) trie
(if (empty? (rest word))
(assoc trie (first word) {:end nil})
(assoc trie (first word)
(process-word {} (rest word))))))
;; Test process-word
(process-word {} "FOOBAR")
What I can't seem to understand is that when I run process-word, I
get the
following output:
{F {O {O {B {A {R {:end nil}}}}}}}
And (keys (process-word {} "FOOBAR")) returns (\F), which makes sense
as I'd expect F to be the key into the hash containing the rest of the
structure.
But if I do (contains? (process-word {} "FOOBAR" ) "F")
It returns false.
Anyone know what's going on?
Also, I'm a complete newbie, so pointers on the above code are
appreciated.