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