Created
March 18, 2018 01:54
-
-
Save lwhorton/f8a7ce8668878b81802e074b5868dd5a to your computer and use it in GitHub Desktop.
why-clojure#2.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; refs are never mutated | |
;; equality is value-based, not identity based | |
;; but you can still compare identity | |
(let [a [1 2 3] | |
b (conj a 4)] | |
(prn a) ;; [1 2 3] | |
(prn b) ;; [1 2 3 4] | |
(= a b) ;; false | |
(= a (drop-last b)) ;; true | |
(identical? a (drop-last b)) ;; false | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = [1, 2, 3] | |
var b = a.push(4) | |
console.log(a) // [1, 2, 3, 4] | |
console.log(b) // 4, heh | |
b = [1, 2, 3, 4] | |
console.log(a == b) // false | |
console.log(a === b) // false | |
;[1,2,3] == [1,2,3] // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment