I should also mention that the reader form is not record-specific - it
works on any Java object:

user=> #java.util.Date[1319639275929]
#<Date Wed Oct 26 09:27:55 CDT 2011>
user=> #java.lang.String["abcdef"]
"abcdef"
user=> #java.awt.Point[1 2]
#<Point java.awt.Point[x=1,y=2]>

On Oct 26, 8:24 am, Alex Miller <a...@puredanger.com> wrote:
> I need to correct that p2 and m1 should not have parens around
> them.... sorry about that.  Seemed obvious when I read it again this
> morning.
>
> The literal reader forms are even trickier in how they treat embedded
> expressions.  They seem to preserve (and not evaluate) the quoted
> forms?
>
> user=> (def p #user.Person[(str "a" "b") "c"])
> #'user/p
> user=> p
> #user.Person{:first (str "a" "b"), :last "c"}    ;; note the embedded
> str here, not "ab"
> user=> (:first p)
> (str "a" "b")           ;; aroo?
>
> Surely, this is not the intended behavior?
>
> On Oct 25, 8:53 pm, Alex Miller <a...@puredanger.com> wrote:
>
>
>
>
>
>
>
> > So I'm catching up with the 1.3 defrecord additions (best docs here
> > afaik:http://dev.clojure.org/display/design/defrecord+improvements-
> > willhttp://clojure.org/datatypesbeupdated?)
>
> > In 1.2, records were constructed only with the positional Java
> > constructor:
> >   (defrecord Person [first last])
> >   (Person. "alex" "miller")
>
> > In 1.3, there are now a plethora of new construction options:
> > Positional:
> > p1)  (Person. "alex" "miller")           ;; "legacy" Java constructor
> > form
> > p2)  (#user.Person["alex" "miller"])   ;; reader form, ns required
> > p3)  (->Person "alex" "miller")          ;; factory function
>
> > Map:
> > m1)  (#user.Person{:first "alex" :last "miller"})   ;; reader form, ns
> > required, default print form
> > m2)  (map->Person {:first "alex" :last "miller"})  ;; factory function
> > m3)  (Person/create {:first "alex" :last "miller"})  ;; static class
> > factory method
>
> > So my question is what my first choice should be when constructing
> > records and needing positional or map forms?  Re positional forms, the
> > p2 reader form requires the ns so is probably more typing than I'm
> > likely to do.  I'm guessing that p3 is now preferred over p1 as it
> > hides the interop form.  So I'll take p3 as the preferred first
> > choice.
>
> > For maps, m1 is the default form serialization form but requires the
> > ns, so I doubt I would choose that first.  m3 clearly seems designed
> > for tool usage and does Java interop, so I'm guessing m2 is the likely
> > preferred first choice.
>
> > Thoughts?

-- 
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

Reply via email to