lists, vecotrs, and hashes all have an empty() method, so (defn clone-coll ([coll clone-item] (clone-item (seq coll) coll clone-item)) ([seq coll clone-item] (if (not seq) (.empty coll) (cons (clone-item (first seq)) (clone-coll (rest seq) coll clone- item)) ) ) )
will clone your collection and in if you pass your replacement function, as clone-item, youc can replace the symbol. On Nov 15, 11:15 pm, Konrad Hinsen <[EMAIL PROTECTED]> wrote: > I am trying to write a function (for use in a macro) that replaces a > given keyword in a form by a given symbol, i.e. > > (replace-symbol :foo :bar form) > > should return the form with all occurences of :foo replaced by :bar. > This turned out to be surprisingly difficult. I started out like this: > > (defn replace-symbol [original replacement form] > (if (= form original) > replacement > (if (islist? form) ...))) > > But there is no islist?, nor anything that looks equivalent. So how > do I test if form is a list? Or a vector? Or a map? For processing > general forms, I'd need to handle all of these, right? Or is there a > simpler way to do it? > > Konrad. --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---