Re:Why Lisp Failed (2010)
by singularity2001 on Sunday July 07, 2019 @04:44PM
(#20377722)
Thanks, that was perfectly interesting. Can you still do it in the above-mentioned way in clojure: ?
[ Parent
| on HN ]
Clojure 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