Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在使用 clojure 项目时遇到了问题,我似乎找不到答案。我正在尝试比较两个符号:
'x 'y
但是当我使用:
(= ('x 'y))
它返回真。与以下相同:
(identical? 'x 'y)
我发现相同的比较内存地址,但我还没有找到为什么'x和'y在比较时返回true?我还没有看到这样的问题,其他大多数帖子都比较数字。
您正在将符号列表与任何内容进行比较。如果只向 = 传递一个参数,则默认返回 true。只需删除符号周围的括号,然后您将比较符号本身。(= 'x 'y).
(= 'x 'y)
(= nil) ; => true ('x 'y) ; => nil ('x #{'x}) ; => 'x ('x #{'z} :one) ; => :one (instance? clojure.lang.IFn 'x) ; => true