dictionary - Destructing a map (using the let keyword) -


as understand it, let keyword, locally binds variables values (supporting sort of pattern matching). receives 2 arguments. first vector symbol want bind , value want bound. comes expression uses value.

in example, first variable person defined:

user=> (def person {:name "jabba" :profession "gangster"}) #'user/person 

now suppose want destruct map using let function:

user=> (let [{name :name} person] (str "the person's name " name)) "the person's name jabba" 

why in [{name :name} person], :name should appear after variable name? wouldn't work:

user=> (let [{:name name} person] (str "the person's name " name)) "the person's name " 

why order this? thought maps defined in either order:

user=> (def map1 {:a 1}) #'user/map1 user=> (def map2 {1 :a}) #'user/map2 

i thought maps defined in either order:

user=> (def map1 {:a 1}) #'user/map1 user=> (def map2 {1 :a}) #'user/map2 

no.

map1 has 1 element; key :a , value 1.
map2 has 1 element; key 1 , value :a.

it's not same.


Comments