support element lookup on transient sets

Description

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.

Environment

Clojure 1.9-aplha17

Activity

Show:
import
September 29, 2017, 6:48 PM

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.

Zach Tellman
September 29, 2017, 7:48 PM

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

import
October 19, 2018, 10:25 AM

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

Steve Miner
March 1, 2019, 1:54 PM

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

Alex Miller
August 20, 2020, 4:08 AM

Fixed and released in org.clojure/data.int-map 1.0.0

Fixed

Assignee

Zach Tellman

Reporter

import

Labels

None

Approval

None

Patch

None

Priority

Major
Configure