Created
July 3, 2012 13:37
-
-
Save jballanc/3039745 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (def foo {:hello "World"}) | |
| (def bar (ref {:hello "World"})) | |
| (map :hello [foo bar]) | |
| ;; => ("World" nil) | |
| (map #(% :hello) [foo bar]) | |
| ;; => ("World" "World") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here I go:
Here, you're applying the key
:hello(which acts like a function in this case, it's casted toclojure.lang.IFn) tofooandbar, so it's something like this:In the second case we're trying to pass the ref
baras parameter to the :hello function but we aren't dereferencingbar, that's why we don't getWorldbut nil.In the other case:
This
is the same as
so the map function ends up doing something like:
This is like this because the hash map
foois casted toclojure.lang.IFn, so it acts like a function which receives:helloas argument which in turn returns the value of the:hellokey.baris a reference, but when used like a function we get the dereferenced value which is{:hello "World"}, so:Then, instead of:
you should do: