Question regarding map/contains?

7 views
Skip to first unread message

Moses

unread,
May 25, 2009, 11:14:24 PM5/25/09
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.


Paul Barry

unread,
May 26, 2009, 9:59:20 AM5/26/09
to clojure-...@googlegroups.com
"F" != \F

user=> (contains? (process-word {} "FOOBAR") "F")
false
user=> (contains? (process-word {} "FOOBAR") \F)
true
Reply all
Reply to author
Forward
0 new messages