Re: surprising behaviour from dissoc on records
Interesting. I think it makes sense in that `dissoc` is a function for removing a kv pair from a map, not a function for setting v to nil given a k. I could definitely see tripping up on this though. On Friday, February 19, 2016 at 8:07:16 AM UTC-8, Alex Miller wrote: > > You can find some of the background for this at > http://clojure.org/reference/datatypes. Records are intended to capture > "application domain information" - where the fields are known. Dissoc'ing > means you are removing not just a value, but the whole "field", and the > implication here is that you devolve from a thing of that "type" to a plain > map. Similarly, "empty" is not implemented on records (because you then > remove all the "fields"). > > This is an intentional choice made by Rich in the design of records. I > think it's reasonable to argue that this creates some surprises in the use > of records - particularly in dissoc and empty. Afaik there is no plan for > this behavior to change, however. > > > > On Friday, February 19, 2016 at 8:30:47 AM UTC-6, Stig Brautaset wrote: >> >> >> Dissoc behaviour on records really surprised me: >> >> user> (defrecord Foo [bar]) >> ;; => user.Foo >> user> (def foo (->Foo nil)) >> ;; => #'user/foo >> user> (dissoc foo :bar) >> ;; => {} >> user> (assoc foo :bar nil) >> ;; => #user.Foo{:bar nil} >> >> It lead to a bug where a component of mine, which I was using to >> dispatch in a multimethod was replaced with an empty map: >> >> >> https://github.com/stig/accounts/commit/f4124b69cfc9fdc201b29f97e33a5b7bd6279e7f >> >> >> *toy project alert* >> >> As an aside, I'm now starting to understand why all the components >> examples use `assoc foo :bar nil` rather than dissoc... >> >> Stig >> >> -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: surprising behaviour from dissoc on records
You can find some of the background for this at http://clojure.org/reference/datatypes. Records are intended to capture "application domain information" - where the fields are known. Dissoc'ing means you are removing not just a value, but the whole "field", and the implication here is that you devolve from a thing of that "type" to a plain map. Similarly, "empty" is not implemented on records (because you then remove all the "fields"). This is an intentional choice made by Rich in the design of records. I think it's reasonable to argue that this creates some surprises in the use of records - particularly in dissoc and empty. Afaik there is no plan for this behavior to change, however. On Friday, February 19, 2016 at 8:30:47 AM UTC-6, Stig Brautaset wrote: > > > Dissoc behaviour on records really surprised me: > > user> (defrecord Foo [bar]) > ;; => user.Foo > user> (def foo (->Foo nil)) > ;; => #'user/foo > user> (dissoc foo :bar) > ;; => {} > user> (assoc foo :bar nil) > ;; => #user.Foo{:bar nil} > > It lead to a bug where a component of mine, which I was using to > dispatch in a multimethod was replaced with an empty map: > > > https://github.com/stig/accounts/commit/f4124b69cfc9fdc201b29f97e33a5b7bd6279e7f > > > *toy project alert* > > As an aside, I'm now starting to understand why all the components > examples use `assoc foo :bar nil` rather than dissoc... > > Stig > > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
surprising behaviour from dissoc on records
Dissoc behaviour on records really surprised me: user> (defrecord Foo [bar]) ;; => user.Foo user> (def foo (->Foo nil)) ;; => #'user/foo user> (dissoc foo :bar) ;; => {} user> (assoc foo :bar nil) ;; => #user.Foo{:bar nil} It lead to a bug where a component of mine, which I was using to dispatch in a multimethod was replaced with an empty map: https://github.com/stig/accounts/commit/f4124b69cfc9fdc201b29f97e33a5b7bd6279e7f *toy project alert* As an aside, I'm now starting to understand why all the components examples use `assoc foo :bar nil` rather than dissoc... Stig -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.