0

I have written the following bit of code

(defn create [title url]
  (when (not-any? clojure.string/blank? '(title url))
    (println "doing stuff")))

However when I call the function

(create "title" "url")

I get the following error and cannot figure out what I am doing wrong

ClassCastException clojure.lang.Symbol cannot be cast to java.lang.CharSequence  clojure.string/blank? (string.clj:279)
2
  • If i change '(title url) to (sequence [title url]) it works so clearly I am misunderstanding what the quote does. Can someone explain or perhaps propose a better way (if it exists)? Commented Jul 13, 2013 at 19:59
  • Or better yet I can just use [title url] Commented Jul 13, 2013 at 20:07

1 Answer 1

3

This is one of the things that also tripped me up when I first started learning clojure. Basically, you should use

(list title url)

The clojure compiler treats

'(title url)

as

(quote (title url))

'quote' does not evaluate anything inside of it, so 'title' and 'url' are just symbols (clojure.lang.Symbols to be precise).

Here's a better explanation than mine: http://blog.8thlight.com/colin-jones/2012/05/22/quoting-without-confusion.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.