Skip to content

Instantly share code, notes, and snippets.

@jjconti
Created June 25, 2015 15:38
Show Gist options
  • Save jjconti/5a26d80ba04e5ff91f03 to your computer and use it in GitHub Desktop.
Save jjconti/5a26d80ba04e5ff91f03 to your computer and use it in GitHub Desktop.
Clojure: maps as keys
;; After https://gist.github.com/jjconti/054e15b5a9a07ecadf33
user=> (def d {:a 1 :b 2 :c 3})
#'user/d
user=> (:b d)
2
user=> (d :b)
2
;; Can dictionaries be keys in another dictionary?
;; What if two dictionaries have each other as keys?
user=> (def metadict {d 42})
#'user/metadict
user=> (assoc d metadict 99)
{{{:c 3, :b 2, :a 1} 42} 99, :c 3, :b 2, :a 1}
user=> (metadict d)
42
user=> (d metadict)
nil
user=> d
{:c 3, :b 2, :a 1}
user=> (def d (assoc d metadict 99))
#'user/d
user=> metadict
{{:c 3, :b 2, :a 1} 42}
user=> d
{{{:c 3, :b 2, :a 1} 42} 99, :c 3, :b 2, :a 1}
user=> (d metadict)
99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment