Why is the dot-dash preferred over dot-prefix when accessing the field of a defrecord in Clojure?
Ex:-
(defrecord Person [name age])
(def person1 (Person. "Ak" 28))
(.-name person1)
"Ak"
(.name person1)
"Ak"
.-
is used to signify field access in Clojure interop, just .
is calling a method.
Either way, as mentioned in a comment on the question, using the keyword as in :name
is the idiomatic way to access the name
field.
The other methods work because records are built partially to support interop with the host language.
Keep in mind that for data modeling in general with Clojure, maps are preferred. Here's a handy flowchart for choosing the right datatype for your situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With