(def a 1) #'us...">

Clojure: "=" compares values ​​in collections, why can't it compare two lists in this case?

See this example:

Clojure 1.4.0 user=> (def a 1) #'user/a user=> (def b 2) #'user/b user=> (= [1 2] [ab]) true user=> (= '(1 2) '(1 2)) true user=> (= '(1 2) '(ab)) false 

Why does the last case not work, and how to make the last case work without having to convert the list to a vector?

Thanks!

+6
source share
1 answer

You are comparing a list containing 1 and 2 with a list containing the characters a and b. Symbols are legal meanings in Clojure. '(ab) is equivalent to (list' a 'b) not (list ab).

  (= '(1 2) (list ab)) 

Perhaps you want to compare.

+15
source

Source: https://habr.com/ru/post/921586/


All Articles