Hi,
On 17 Nov., 13:05, Konrad Hinsen <[EMAIL PROTECTED]> wrote:
> (defn replace-syms
> [sym-map expr]
> (let [replace #(replace-syms sym-map %)]
> (cond (contains? sym-map expr) (get sym-map expr)
> (list? expr) (map #(replace-syms sym-map %) expr)
> (vector? expr) (into [] (map replace expr))
> (map? expr) (into {} (map replace (seq expr)))
> (set? expr) (set (map replace expr))
> true expr)))
vals returns a clojure.lang.APersistentMap$ValSeq, which
is not a list. Hence list? returns false and you get the true
branch, ie. the thing itself.
I tried the following approach, which also doesn't work, because
clojure.lang.PersistentHashMap$LeafNode does not return
something of a similar type or a vector when called with empty,
but a list. Hence the following doesn't work for maps. Note
also the annoying special case for the list...
(defn replace-syms
[sym-map expr]
(cond
(contains? sym-map expr) (sym-map expr)
(list? expr) (map #(replace-syms sym-map %) expr)
(coll? expr) (into (empty expr)
(map #(replace-syms sym-map %)
expr))
:else expr))
I know. It doesn't help much, but it shows, that you have to take
care to distinguish the abstraction vs. the specific implementation.
Sincerely
Meikel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---