Java – in clojure, is (=’a’a) refers to ‘the same atom’?

In some implementations of Common Lisp, we can say that for the following expressions

(eq 'a 'a)

It's true, because 'A and' a are "the same atom"

This may be implementation dependent, but it seems that the phrase (used in popular LISP textbooks) assumes that atoms of the same value are stored in the same location in memory

In Java, two internship strings with the same value are stored in the same location in memory

Now clojure on the JVM inherits the legacy of Java, but say that two atoms in clojure (on the JVM) have the same value. Is it the same atom? (that is, how does clojure's atomic storage mechanism work?)

Solution

First, "atom" has a different meaning from most other lisps in clojure See http://clojure.org/atoms

Clojure's = function uses value - based equality Therefore, two objects with the same value will be =, even if they are stored in different locations in memory

To test whether two objects are actually the same object, at the same address in memory, using the same? Function

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>