Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using clojure.contrib.strint with a string defined elsewhere

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

like image 594
Johnny Brown Avatar asked Mar 15 '26 13:03

Johnny Brown


1 Answers

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}")))
like image 129
ivant Avatar answered Mar 17 '26 02:03

ivant