4 ms·
Thanks, that was perfectly interesting. Can you still do it in the above-mentioned way in clojure: ? (defparameter a '((color brown) (nam
by singularity2001 7y ago
Thanks, that was perfectly interesting. Can you still do it in the above-mentioned way in clojure: ?
(defparameter a '((color brown)
(name fred)))
- LandR 7y agoClojure data structures are immutable, so getters and setters are mostly out. In CLojure, maps are functions and keywords are also functions. But you could do: (def foo {:color "brown" :name "fred"}) Anytime you want to get the color out you can just call the :color function and pass the map (:color foo) => "brown" (:name foo) => "fred" Likewise, we can call the map as the function and pass the key as the argument (foo :name) => "fred" We also have nice ways to destructure and bind values in maps when passed as parameters to functions (defn my-func [{:keys [color name]}] (println "Color: " color) (println "Name: " name)) (my-func foo) => Color: brown Name: fred