On Tue, Oct 7, 2008 at 2:32 PM, Stuart Halloway <[EMAIL PROTECTED]>wrote:
> > Hi Brian, > > (1) What does it mean to be equal on id and not equal on the other > fields? If two fields claim the same id but a different name, how > would you know which one to keep? I guess it could depend on the situation and you may not care about the other fields at all, only on the id. I'm used to Java/Ruby when you define an equals and hashcode method that determines equality which very well may be a subset of the total attributes on an object. (2) Given some answer to #1, why not store the structs in a map under > id? I could, but does this mean that I couldn't store the place objects in a set to dedup the places? It would appear that a struct uses all of the attributes of the map to determine equality. I was hoping I could overwrite equality for a given struct. > > > (3) For the geocoded place struct, I would be tempted to just create a > separate defstruct. Nothing in Clojure prevents the two different > kinds of structures from being substituted for one another. You could > look into make-hierarchy, etc. plus defmulti if you find that you need > inheritance-like behavior for method dispatch. Yes, I was just being somewhat lazy with this. If I define 10 attributes for a given struct and wanted to use all of those plus 3 more in a new struct I didn't want to have to write out those original 10 attributes again. Thanks. > > > Stuart > > > I'm attempting to learn Clojure with a long history of OO and have > > some > > questions. I've created a defstruct for a place type object like: > > > > (defstruct place :id :name :street :city :state :zip) > > > > I want to write a function that would take a list of places and remove > > the duplicates. Duplicates are defined by places having the > > same :id. > > I created a 'place' namespace and attempted to create a function > > called '=' that would only use the :id to compare two places, however, > > I was not about to create such a function name. Is there a preferred > > function name for equality in this case? > > > > Coming from an OO background and wanting a geocoded-place > > struc is there a way to "inherit" from the place struct? Something > > like take all of the existing keys from the place struct and also add > > :latitude & :longitude? > > > > 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---