On Oct 23, 2:10 pm, andrei <andrei.zhabin...@gmail.com> wrote:
> I modified procedure a bit to see interim results, and it's output
> confused me even more.
>
> (defn replace-map
>   "Replaces substrings in s from (keys m) by (vals m). "
>   [s m]
>   (loop [cur-str s, ks (keys m)]
>     (if (empty? ks)
>       cur-str
>       (let [replaced (.replace s (first ks) (m (first ks)))]
>         (println "STR BEFORE: " cur-str "; STR AFTER: " replaced)
>         (recur replaced
>                (rest ks))))))
>
> Can anybody explain what's going on? I'm very very confused.

You're calling replace on the original string every time.  You want
(.replace cur-str ...) rather than (.replace s ...).

- Chris

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to