Re: On the importance of recognizing and using maps

2009-03-12 Thread Jeff Rose
Konrad Hinsen wrote: > On Mar 12, 2009, at 10:59, Jeff Rose wrote: > >>> My main conclusion is that Clojure's system is a lot more flexible >>> but also a lot more fragile. Any function can modify data of any >>> "type" (as defined by metadata), even without being aware of this. >> Modifying type

Re: On the importance of recognizing and using maps

2009-03-12 Thread Konrad Hinsen
On Mar 12, 2009, at 10:59, Jeff Rose wrote: >> My main conclusion is that Clojure's system is a lot more flexible >> but also a lot more fragile. Any function can modify data of any >> "type" (as defined by metadata), even without being aware of this. > > Modifying type tags without being aware o

Re: On the importance of recognizing and using maps

2009-03-12 Thread Jeff Rose
Konrad Hinsen wrote: > On 11.03.2009, at 23:34, Chouser wrote: > >> Interacting directly with a class dict feels a little dirty, because >> you could be circumventing the API provided by the class methods, >> making it easy to get the object into a bad state. Clojure's maps >> being immutable re

Re: On the importance of recognizing and using maps

2009-03-12 Thread Konrad Hinsen
On 11.03.2009, at 23:34, Chouser wrote: > Interacting directly with a class dict feels a little dirty, because > you could be circumventing the API provided by the class methods, > making it easy to get the object into a bad state. Clojure's maps > being immutable reduces the amount of trouble y

Re: On the importance of recognizing and using maps

2009-03-11 Thread Cosmin Stejerean
On Wed, Mar 11, 2009 at 5:34 PM, Chouser wrote: [...] > > Defining a instance method for a Python class allows you to connect > some code to your data, which internally uses a type pointer from the > instance to the class. In Clojure you can put functions directly in > the metadata (as clojure.z

Re: On the importance of recognizing and using maps

2009-03-11 Thread Chouser
On Wed, Mar 11, 2009 at 1:54 PM, Cosmin Stejerean wrote: > > IMHO a big reason Python programmers don't typically treat objects like is > maps/dictionaries is that the set of things found in the map (dictionary) > for that object (__dict__) are just a small subset of the interesting > attributes

Re: On the importance of recognizing and using maps

2009-03-11 Thread Cosmin Stejerean
On Wed, Mar 11, 2009 at 12:00 PM, Konrad Hinsen wrote: > > On Mar 8, 2009, at 18:53, Rich Hickey wrote: > > > I know people usually think of collections when they see vector/map/ > > set, and they think classes and types define something else. However, > > the vast majority of class and type insta

Re: On the importance of recognizing and using maps

2009-03-11 Thread Konrad Hinsen
On Mar 8, 2009, at 18:53, Rich Hickey wrote: > I know people usually think of collections when they see vector/map/ > set, and they think classes and types define something else. However, > the vast majority of class and type instances in various languages are > actually maps, and what the class/

Re: On the importance of recognizing and using maps

2009-03-09 Thread mikel
On Mar 9, 7:46 am, Rich Hickey wrote: > On Mar 9, 2:19 am, Mark Engelberg wrote: > > > > > > > On Sun, Mar 8, 2009 at 10:44 PM, mikel wrote: > > > Clojure doesn't have to provide these facilities (though I wouldn't > > > mind if it did); it just needs to stay out of my way when I decide I > >

Re: On the importance of recognizing and using maps

2009-03-09 Thread Rich Hickey
On Mar 9, 2:43 am, mikel wrote: > On Mar 9, 1:19 am, Mark Engelberg wrote: > > > On Sun, Mar 8, 2009 at 10:44 PM, mikel wrote: > > > Clojure doesn't have to provide these facilities (though I wouldn't > > > mind if it did); it just needs to stay out of my way when I decide I > > > need to add

Re: On the importance of recognizing and using maps

2009-03-09 Thread Rich Hickey
On Mar 9, 2:19 am, Mark Engelberg wrote: > On Sun, Mar 8, 2009 at 10:44 PM, mikel wrote: > > Clojure doesn't have to provide these facilities (though I wouldn't > > mind if it did); it just needs to stay out of my way when I decide I > > need to add them. > > Yeah, as much as I like maps, I fe

Re: On the importance of recognizing and using maps

2009-03-09 Thread Steve Fisher
On Mar 8, 7:59 pm, Brian Carper wrote: > On Mar 8, 10:53 am, Rich Hickey wrote:> > > > In looking at some of the libraries, I am a bit concerned that maps > > are not being used when the logical entity is in fact a map. > > One time I find myself abusing vectors where maps would be better is >

Re: On the importance of recognizing and using maps

2009-03-09 Thread Paul Stadig
On Sun, Mar 8, 2009 at 9:59 PM, Brian Carper wrote: > > On Mar 8, 10:53 am, Rich Hickey wrote:> >> In looking at some of the libraries, I am a bit concerned that maps >> are not being used when the logical entity is in fact a map. > > One time I find myself abusing vectors where maps would be be

Re: On the importance of recognizing and using maps

2009-03-08 Thread mikel
On Mar 9, 1:19 am, Mark Engelberg wrote: > On Sun, Mar 8, 2009 at 10:44 PM, mikel wrote: > > Clojure doesn't have to provide these facilities (though I wouldn't > > mind if it did); it just needs to stay out of my way when I decide I > > need to add them. > > Yeah, as much as I like maps, I fe

Re: On the importance of recognizing and using maps

2009-03-08 Thread Mark Engelberg
On Sun, Mar 8, 2009 at 10:44 PM, mikel wrote: > Clojure doesn't have to provide these facilities (though I wouldn't > mind if it did); it just needs to stay out of my way when I decide I > need to add them. Yeah, as much as I like maps, I feel like there are several common uses cases for maps th

Re: On the importance of recognizing and using maps

2009-03-08 Thread mikel
On Mar 8, 12:53 pm, Rich Hickey wrote: > Recently it was said in a thread: > > "You can do a lot of that in Clojure, too, but, unless I'm mistaken, > there are some arbitrary limits as things stand right now. ... you can > have any kind of structure you want, as long as it's a map, set, or > s

Re: On the importance of recognizing and using maps

2009-03-08 Thread Stephen C. Gilardi
On Mar 8, 2009, at 9:38 PM, Rich Hickey wrote: Do you have a case where the map-unpacking dominates the I/O time? Or is this just a speculative optimization? I was talking about the distinction between sending N value sets across the JDBC interface in one call vs. in N calls. Unpacking maps

Re: On the importance of recognizing and using maps

2009-03-08 Thread Rich Hickey
On Mar 8, 10:10 pm, "Stephen C. Gilardi" wrote: > On Mar 8, 2009, at 9:13 PM, Shawn Hoover wrote: > > > Close... you can assoc new keys into a struct instance, but you > > can't dissoc any of the basis keys. > > That's right. > > Given: > user=> (defstruct foo :a :b) > #'user/fo

Re: On the importance of recognizing and using maps

2009-03-08 Thread Stephen C. Gilardi
On Mar 8, 2009, at 9:13 PM, Shawn Hoover wrote: Close... you can assoc new keys into a struct instance, but you can't dissoc any of the basis keys. That's right. Given: user=> (defstruct foo :a :b) #'user/foo user=> (def t (struct foo 3)) #'user/t dissoc of

Re: On the importance of recognizing and using maps

2009-03-08 Thread Brian Carper
On Mar 8, 10:53 am, Rich Hickey wrote:> > In looking at some of the libraries, I am a bit concerned that maps > are not being used when the logical entity is in fact a map. One time I find myself abusing vectors where maps would be better is in a situation where I have to retrieve key/value pair

Re: On the importance of recognizing and using maps

2009-03-08 Thread Rich Hickey
On Mar 8, 9:05 pm, "Stephen C. Gilardi" wrote: > On Mar 8, 2009, at 1:53 PM, Rich Hickey wrote: > > > First up is contrib.sql, where insert-rows and insert-values both take > > a vector of column names followed by vectors of unlabeled values that > > must be in the same order as the correspondi

Re: On the importance of recognizing and using maps

2009-03-08 Thread Shawn Hoover
On Sun, Mar 8, 2009 at 6:13 PM, Dan wrote: > > > I'm pretty sure structs are only appropriate for when you need to eek > > the absolute last iota of performance out of a collection, in which case > > they can provide greater speed than maps. But since the list of keys is > > fixed, it means it's

Re: On the importance of recognizing and using maps

2009-03-08 Thread Stephen C. Gilardi
On Mar 8, 2009, at 1:53 PM, Rich Hickey wrote: First up is contrib.sql, where insert-rows and insert-values both take a vector of column names followed by vectors of unlabeled values that must be in the same order as the corresponding columns. I would hope never to have such fragile things as t

Re: On the importance of recognizing and using maps

2009-03-08 Thread Mark Allerton
I'm kind of a newb to these parts, but I disagree somewhat with Phil that structmaps are only useful as a performance optimization. It also seems to me that because they make it convenient to create positional constructors for map structures, they make life much easier to concisely build data str

Re: On the importance of recognizing and using maps

2009-03-08 Thread Dan
> I'm pretty sure structs are only appropriate for when you need to eek > the absolute last iota of performance out of a collection, in which case > they can provide greater speed than maps. But since the list of keys is > fixed, it means it's more effort to add or rename a key than it is with > a

Re: On the importance of recognizing and using maps

2009-03-08 Thread Phil Hagelberg
Dan writes: >> I guess I want to advocate - don't merely replicate the things with >> which you are familiar. Try to do things in the Clojure way. If your >> logical structure is a mapping of names to values, please use a map. > > I tend to replace every instance of creating classes with creatin

Re: On the importance of recognizing and using maps

2009-03-08 Thread David Nolen
Structs are maps with shared keys and positional constructors as Rich mentions in the original post. I think Rich is saying that maps should indeed "be abused" ;) By building all "higher level" structures on top of them, consumers are guaranteed not only your custom functionality, but all the func

Re: On the importance of recognizing and using maps

2009-03-08 Thread Dan
> I guess I want to advocate - don't merely replicate the things with > which you are familiar. Try to do things in the Clojure way. If your > logical structure is a mapping of names to values, please use a map. I tend to replace every instance of creating classes with creating structs which, if

Re: On the importance of recognizing and using maps

2009-03-08 Thread Stuart Sierra
On Mar 8, 1:53 pm, Rich Hickey wrote: > I really appreciate the work everyone is doing, just trying to > maintain 'everything works with everything' with a nudge towards more > consistent use of maps. Don't build your API on an island. And a good nudge it is! This reminds me of Steve Yegge's ar