What is the difference between quote and string in this case with Clojure?

The following two commands print the same thing in repl:

user=> (println "(foo bar)")
(foo bar)
nil
user=> (println (quote (foo bar))
(foo bar)
nil

So, in this case, what's the difference between a quote and a string?

Edit: (+ 3 2) and (+ (quote 3) 2)match. The docs say that the quote gives an invaluable form (so maybe I am answering my question here, but please check) that the quote is an optimization with a lazy rating?

+3
source share
2 answers

They are really different things:

user=> (class '(foo bar))
clojure.lang.PersistentList
user=> (class "foo bar")
java.lang.String

Even if they can have an identical result println, they do not match.

For the rest, @bmillare is right: you are not quotetoo lazy, you quote literal expressions.

+10
source

, , , println , , . , , prn (pr, )

 user=> (prn "(foo bar)")
 "(foo bar)"
 nil
 user=> (prn (quote (foo bar)))
 (foo bar)
 nil

- . , (+ 3 2) (+ ( 3) 2), , , . , . (http:// clojure.org/reader) , . - .

+5

All Articles