it is expected behavior, because update-in calls the supplied function with
the value it finds in the map as the first argument, so your first call
ends up being

(remove [1 2 3] #{2})

Since ([1 2 3] 2) = 3 and is truthy, the result is ().

In your second case you're using (partial remove #{2}), so the result is
'(1 3), which is then turned into a vector by vec.


On Thu, May 29, 2014 at 10:00 AM, Stuart Fehr <stuart.f...@gmail.com> wrote:

> I am not sure if this is considered a "bug" or if it is simply expected
> behavior, so I thought I would ask the list for clarification.
>
> I have this test which passes and shows the strange behavior that I am
> encountering:
>
> (deftest update-in-and-remove
>   ;; The leaf value becomes and empty list instead of [1 3]
>   (is (= {:mykey {:myotherkey '()}}
>          (update-in {:mykey {:myotherkey [1 2 3]}} [:mykey :myotherkey]
> remove #{2})))
>   ;; Forcing a vector results in the behavior that I would expect
>   (is (= {:mykey {:myotherkey [1 3]}}
>          (update-in {:mykey {:myotherkey [1 2 3]}} [:mykey :myotherkey]
> (comp vec (partial remove #{2}))))))
>
> I think this behavior is due to the use of apply in the definition of
> update-in and I think (but haven't tested) adding a partial to the
> non-recursive clause will fix this:
>
> https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L5687
>
> However, I don't want to submit a "fix" if this is the expected behavior.
> Thoughts?
>
> --
> 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.
>



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

Reply via email to