On Fri, Jan 18, 2013 at 3:37 PM, Stephen Compall <stephen.comp...@gmail.com> wrote: > On Jan 18, 2013 2:36 PM, "Ben Wolfson" <wolf...@gmail.com> wrote: >> >> I could just extend ILookup, which contains only valAt, but I'd also >> >> like to be able to implement containsKey and entryAt, which AFAICT are >> >> only found in Associative. > > Associative also contains > > Associative assoc(Object key, Object val); > > I would propose, as a law, that anAssociative.assoc(k, v).valAt(k) = v. Do > you satisfy that? (An enumeration of Associative laws would be helpful > here.)
No, I don't: assoc is a is a no-op (as is without). Both assoc and without are, in fact, only there to prevent set/rename-keys and a few other functions from blowing up (set/rename-keys is *also* a no-op with those definitions of assoc and without---but given the definition of valAt, rename-keys being a no-op is correct). However, it would certainly be possible to support that behavior while retaining the nonsensicality of calling seq on the structures: (defn constmap [o & [override]] (let [override (or override {})] (reify clojure.lang.Associative (containsKey [this _] true) (entryAt [this k] (if (.containsKey override k) (.entryAt override k) (clojure.lang.MapEntry. k o))) (valAt [this k] (second (.entryAt this k))) (assoc [this k v] (constmap o (.assoc override k v)))))) > Anyway, anyone is free to assume that, given an IPersistentMap (or what have > you), all of the laws of its superclasses are also implied. Yes, that is probably so. > So I think > inheriting Seqable is a positive statement of this law: > > anAssociative.entryAt(k) returning entry E, > implies that (seq anAssociative) contains E. > > But I cannot be sure. Without this law, though, you are basically left with > (pure) function. Right: I basically want (constantly 'foo), but supporting the map interface. Or, rather, a subset of the map interface as it's currently defined: it seems odd to me that being able to answer the question "do I contain x?" implies "I can enumerate my contents". -- Ben Wolfson "Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure." [Larousse, "Drink" entry] -- 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