I'm new to clojure, and I'm trying to use clojure.contrib.strint to build a URL. for example I might use this for a google search:
(def search_base_url "http://www.google.com/search?hl=en&q=~{query}")
(defn search_url [search_term]
(let [query (.replaceAll search_term "\\s+" "+")]
(<< search_base_url)))
But this gives me the compiler error:
error: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: No matching method found: indexOf for class clojure.lang.Symbol.
I think strint uses indexOf a few times, so somehow I'm not giving the << function what it wants, it seems.
I've also tried (def search_base_url '(<< "http://myurl.com?~{params}")), but then I can't figure out how to evaluate that form in the context of my let. I could just put the string in the search_url function, but that feels inferior to me and I'm hoping the answer to this will help me understand clojure a bit better.
Thanks
The problem is, that the "<<" macro expects a string, not something which evaluates to string. That is, it tries to call .indexOf on the symbol named "search_base_url", instead of on its value.
So one way to fix this is:
(defn search-url [search-term]
(let [query (.replaceAll search-term "\\s+" "+")]
(<< "http://www.google.com/search?hl=en&q=~{query}")))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With