Quoting Confusion

Why does this series of clojure commands return false rather than true? What is the difference between the result of statement 1 "C" and 2 "(quote C)"?

; SLIME 2009-03-04
user> ('A 'B 'C)
C
user> (last '('A 'B 'C))
(quote C)
user> (= ('A 'B 'C) (last '('A 'B 'C)))
false

This question is somewhat similar to How does clojure quote syntax work?

+3
source share
2 answers

In Clojure (and other Lisps) 'is a shortcut to the form (quote ...). Therefore, when Clojure sees this:

('A 'B 'C)

which is "translated" by the reader into:

((quote A) (quote B) (quote C))

Each of these forms of quotes evaluates to a character, therefore (quote A)evaluates a character named A. In Clojure, characters are functions and can be used, therefore it ((quote A) (quote B) (quote C))is actually a function call. From the docs:

", , IFn invoke() () ( ). ('mysym my-hash-map: none) as ( my-hash-map 'mysym: none).

, C .

,

'('A 'B 'C)

(quote ((quote A) (quote B) (quote C)))

, , quote ( A, B, C).

, (last '('A 'B 'C)) (quote C). , , C C, (quote C) - .

:

user=> (class ('A 'B 'C))
clojure.lang.Symbol
user=> (class (last '('A 'B 'C)))
clojure.lang.PersistentList
user=> 

, !

+7

('x' y) , . '(x y), x y. TWICE '(' x 'y), ( x): , x.

+1

All Articles