cnuernber / dtype-next

A Clojure library designed to aid in the implementation of high performance algorithms and systems.
Other
328 stars 20 forks source link

`argops/arggroup` returns a non-functional map 😉 #74

Closed harold closed 1 year ago

harold commented 1 year ago

https://github.com/cnuernber/dtype-next/blob/7735b40fb501eb4ca6ab28b85d22c994cb9c8d14/src/tech/v3/datatype/argops.clj#L588

> (def slot->idx (tech.v3.datatype.argops/arggroup [1 2 3 1 2 3]))
#'slot->idx
> slot->idx
{1 [0 3], 2 [1 4], 3 [2 5]}

Nice

> (get slot->idx 1)
[0 3]

Also nice, but...

> (slot->idx 1)
Execution error (ClassCastException) at eval42636 (form-init17704197184208595750.clj:126).
class java.util.LinkedHashMap cannot be cast to class clojure.lang.IFn (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; clojure.lang.IFn is in unnamed module of loader 'app')

Not a big deal, obviously, because can just call get. Caught me out for a second though, because hit this in a heavily threaded context that was swallowing errors.

cnuernber commented 1 year ago

Hmm - you are right. That cannot be the default.

cnuernber commented 1 year ago

The approach I want to try is to have a wrapper of Map that makes it functional.

harold commented 1 year ago

I’m in favor of that. I had a similar thought but didn’t know the best approach. Interested to see what you come up with.