Welcome! Please see the About page for a little more info on how this works.

0 votes
in data.int-map by

This is related to https://dev.clojure.org/jira/browse/CLJ-700

contains? doesnt work on transient collections

Now of course the expectation of how data.int-map should work is the same as with a general set so I dont complain there. However, a workaround shown in this thread: https://groups.google.com/forum/#!topic/clojure/lQVmZ-jcdiU is to use the set directly as a function:

;; this works
((transient #{1 2 3}) 2)
;=> 2

;; this doesnt :(
((transient (int-set #{1 2 3})) 2)
;=> CompilerException java.lang.IllegalArgumentException: contains? not supported on type: clojure.data.int_map.TransientIntSet

I checked the code and the TransientIntSet supports the contain method of the TransientIntSet interface which could be used directly and return the correct value but it is definitely not idiomatic to recur to interop nor have to look that around for this specific case.

6 Answers

0 votes
by

Comment made by: ztellman

Correct me if I'm wrong, but the only fix for this is a change to Clojure's implementation, right? I don't see anything that can be done in this library to change this behavior.

0 votes
by

Comment made by: carocad

certainly "contains?" behavior cannot be fixed inside this library. However this ticket is about using transient sets as functions. (see description examples)

Clojure's transient set allow looking up a key if the set is used as a function. Nevertheless, data.int-map transient-sets internally uses "contains?" whenever it is invoked as a function. Thus breaking the expected behavior of sets.

Clojure handles this use case by calling the "get" function if the set is used as a function: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/APersistentSet.java#L50. Therefore no call to "contains?" is ever dispatched.

The current behavior of int-map sets forces the user to discriminate which set type is being used such that the right function is called.

0 votes
by

Comment made by: ztellman

Okay, that make sense. I'll update the library accordingly.

0 votes
by

Comment made by: carocad

Clojure 1.9 solved the issue of transients by adding a new interface with the necessary methods. So I the workaround described here is no longer valid and I think that the general expectation would be for int-map to implement that interface as well

0 votes
by

Comment made by: steveminer@gmail.com

Looks like this was fixed by commit 36846ff, and commit 2d5d0e5.

0 votes
by
Reference: https://clojure.atlassian.net/browse/DIMAP-14 (reported by alex+import)
...