Huh! I checked several times to pass to recur replaced string, but
didn't noticed that I'm passing wrong string to .replace itself. Thank
you!
On Oct 23, 10:12 pm, Chris Perkins wrote:
> On Oct 23, 2:10 pm, andrei wrote:
>
> > I modified procedure a bit to see interim results, and it's output
>
On Oct 23, 2:10 pm, andrei 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
>
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))
My purpose is to write function for replacing multiple substrings in a
string. Here's my approach:
(defn replace-map
"Replaces substrings in s from (keys m) by (vals m). "
[s m]
(loop [cur-str s, rps m]
(if (empty? rps)
cur-str
(recur (.replace s (first (first rps)) (second (