Idiomatic use of records?

2013-07-25 Thread Sean Corfield
I tend to use plain ol' maps for data structures but was showing someone defrecord the other day and had some questions about idiomatic usage: Given: (defrecord Point [x y]) Which constructor form is considered more idiomatic: (Point. 10 10) or (-Point 10 10) Which accessor form is considered

Re: Idiomatic use of records?

2013-07-25 Thread Neale Swinnerton
Chas Emerick's excellent clojure type flowchart[1] is my goto for when to use a defrecord over deftype / plain 'ol map. Since the criteria to choose defrecord is basically 'do you need it to behave like a clojure immutable map, but with enhanced protocols support' then I'd argue that the

Re: Idiomatic use of records?

2013-07-25 Thread Baishampayan Ghose
The second form in both the cases. The first ones IMHO are implementation detail. ~BG On Thu, Jul 25, 2013 at 9:48 PM, Sean Corfield seancorfi...@gmail.com wrote: I tend to use plain ol' maps for data structures but was showing someone defrecord the other day and had some questions about

Re: Idiomatic use of records?

2013-07-25 Thread Steven Degutis
+1 to that interpretation On Thu, Jul 25, 2013 at 12:03 PM, Baishampayan Ghose b.gh...@gmail.comwrote: The second form in both the cases. The first ones IMHO are implementation detail. ~BG On Thu, Jul 25, 2013 at 9:48 PM, Sean Corfield seancorfi...@gmail.com wrote: I tend to use plain

Re: Idiomatic use of records vs. maps

2011-05-31 Thread David McNeil
A couple of aspects of records that I have found useful: * they provide a type for dispatching. Rather than rooting around in the map to find out what it is, a multi-method can dispatch directly on the type of the object. * having a central definition of the main keys contained in the structure

Re: Idiomatic use of records vs. maps

2011-05-31 Thread Ken Wesson
On Tue, May 31, 2011 at 11:30 AM, David McNeil mcneil.da...@gmail.com wrote: A couple of aspects of records that I have found useful: * they provide a type for dispatching. Rather than rooting around in the map to find out what it is, a multi-method can dispatch directly on the type of the

Re: Idiomatic use of records vs. maps

2011-05-30 Thread James Reeves
On 30 May 2011 02:02, Ken Wesson kwess...@gmail.com wrote: I don't think either is non-idiomatic, but I'd probably just use the map. It's shorter and simpler code, more widely interoperable with other Clojure facilities, and the member access speedup using a record is unlikely to matter much

Idiomatic use of records vs. maps

2011-05-29 Thread James Reeves
The documentation on records seems to indicate that they be used in place of structs, but is there any advantage to using a record if no protocols are assigned to it? For example, I've defined a TcpServer record as part of a library I'm developing: (defrecord TcpServer [port host

Re: Idiomatic use of records vs. maps

2011-05-29 Thread Ken Wesson
On Sun, May 29, 2011 at 8:56 PM, James Reeves jree...@weavejester.com wrote: The documentation on records seems to indicate that they be used in place of structs, but is there any advantage to using a record if no protocols are assigned to it? Access to a record's in-definition members should