You can refer-in the first (factory function) to another namespace; for the 
second you'd have to import the class. I prefer the first. The third is 
special syntax for the reader.

As to the last question, I don't know, but it allows you to define your 
own. For example, 

    (defrecord Book [title author] 
      clojure.lang.IFn 
      (invoke [this x] (get this x)) 
      (invoke [this x not-found] (get this x not-found)))

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

    (b :title) ;=> "Lord of the Rings"

But you could alter the behavior as desired.


On Wednesday, April 9, 2014 1:51:01 PM UTC-5, 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"}
>
>
> Questions :
> 1) The second version is referred to as the "original" version so I'm 
> wondering which is the preferred method. 
> 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))
> 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.
>
> 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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to