On Nov 15, 2008, at 5:15 PM, Konrad Hinsen 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?

You can use list? vector? and map?. To find all predicates that  
clojure defines, you can do this search:

user=>(find-doc "[?]")

--Steve


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to