On 4/9/14, 12:51 PM, Anthony Ortiz wrote:
I see that there are several ways of instantiating a record :


(->Book "Lord of the Rings", "Tolkien")

(Book. "Lord of the Rings", "Tolkien")

#user.Book{:title "Lord of the Rings", :author "Tolkien"}

You missed one:

(map->Book {:title "Lord of the Rings", :author "Tolkien"})


Questions :
1) The second version is referred to as the "original" version so I'm wondering which is the preferred method.
The helper constructor fns are preferred and not the older dot form. IIRCC you have to import the record to use that constructor, but with the constructor fns you can :require them like any other clojure fn. Not a big deal, but it is nicer and doesn't let the interop abstraction bleed into your ns declarations.

2) Why is the third version not within a list? I thought that for the language to consider something "callable" it had to be the first argument in a list (eg : (+ 1 2))
Your third version is using tagged literals and so the semantics of the reader is different in that case. See http://clojure.org/reader#The%20Reader--extensible%20data%20notation%20(edn)
3) The record that is returned via (def b [version of choice goes here]) is treated as a map when using the form (:title b) but doesn't treat it as a map when using the form (b :title) which seems pretty inconsistent to me; is there are valid reason for this inconsistency? I'm sure I'm missing something.

I agree that it is inconsistent. I don't know why that inconsistency exists but I would be curious to know the reason if someone on the list knows... As A. Webb just pointed out you can add that behavior yourself if you want to.

Thanks!
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com <mailto:clojure+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to