In some implementations of Common LISP we can say that for the following expression
(eq 'a 'a)
Is true
because 'a
and 'a
are the "same atom".
This may be implementation dependent, but it seems the phrase (used in a popular LISP teaching book) assumes that atoms of the same value are stored in the same location in memory.
In Java, two interned strings of the same value are stored in the same location in memory.
Now Clojure on the JVM inherits Java's legacy, but is it true to say that two atoms in Clojure (on JVM) having the same value are the same atom? (ie how does Clojure's atom storage mechanism work?)
First, "atom" has a different meaning in Clojure than in most other Lisps. See http://clojure.org/atoms
Clojure's =
function uses value-based equality. So two objects with equal values will be =
even if they are stored in different locations in memory.
To test if two objects are actually the same object, at the same address in memory, use the identical?
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With