This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-30
Channels
- # announcements (12)
- # babashka (25)
- # biff (30)
- # cherry (34)
- # cider (46)
- # clj-kondo (23)
- # clojure (37)
- # clojure-berlin (6)
- # clojure-europe (12)
- # clojure-nl (4)
- # clojure-norway (6)
- # clojure-uk (2)
- # clojurescript (8)
- # conjure (1)
- # cursive (4)
- # data-science (11)
- # datalevin (12)
- # datascript (15)
- # emacs (2)
- # events (1)
- # fulcro (14)
- # graalvm (16)
- # gratitude (23)
- # honeysql (11)
- # jobs (2)
- # jobs-discuss (14)
- # kaocha (1)
- # leiningen (8)
- # nbb (45)
- # off-topic (7)
- # portal (8)
- # re-frame (9)
- # releases (2)
- # shadow-cljs (24)
- # squint (5)
- # tools-build (17)
- # tools-deps (7)
- # vim (5)
I'm working with Java interop, and have a type implementing java.util.Collection
. The thing is, no matter what I try, I can't call its .add
method. I'm getting the following error instead:
No matching method add found taking 1 args for class
org.camunda.bpm.model.xml.impl.type.child.ChildElementCollectionImpl$1
I can call every other method in Collection
, like .isEmpty
, .clear
or even .addAll
! But there doesn't seem to be a way to call .add
without getting the error.
(def my-object (...))
(isa? (.getClass my-object) java.util.collection) ; => true
(.clear my-object) ; => works
(.addAll my-object [...]) ; => works
(.add my-object ...) ; => Throws the error above
(seq (.getMethods (.getClass my-object))) ; => This lists "add" among the class' methods
I honestly don't have a clue what's going on there, what could be causing this strange behavior? 😅The error message seems straightforward. Does the add
that you find in the class’ methods take zero arguments or more than 1 argument?
Maybe you have some stale version of the impl loaded into your runtime that is different from what you have in your source code now?
Try type hinting my-object
with ^java.util.Collection
Type inference will work from the type of your object but that may actually be too specific here and you're getting into module visibility issues or something
What’s a good way to diff dependencies between different clj aliases? I am using
diff <(clojure -X:deps tree) <(clojure -X:my-stuff:deps tree)
But those produce the same thing. I see that my-stuff is pulling in additional dependencies, though so I expected them to be differentclojure -X:deps tree :aliases '[:my-stuff]'
☝️:skin-tone-2: You beat me to it -- for -X:deps
you need to specify the aliases as an argument to the command.
oh yeah, that too
but use list
instead of tree
Also definitely use clojure
and not clj
here, as rlwrap messes up the terminal state after exiting with this command.
try -X:deps list
instead
Hey everyone! What would be an idiomatic way to determine whether a map is a “submap” of another map? I would need to work recursively, but not require that all keys be present, so e.g. {:b 2 :c {:e 4}}
would be considered a submap of {:a 1 :b 2 :c {:d 3 :e 4}}
yeah, that’s the one thing I’ve struggled with as well 😅
@U050ECB92 it’s not really clear to me how I’d use that library to accomplish what I need.. do you think you could point me in the right direction? 🙂 FWIW, I’m not using this in the context of testing
agreed… calling that with one argument (like my map) returns a matcher.. but I’m not sure how to use that to match against the other map
(let [result# (core/match matcher# actual#)
match?# (core/indicates-match? result#)]
from the match?
clojure.test extensionnice! this looks like a way forward :thumbsup: although the docstring starts with “For internal use”… they’ll never catch me!
You can flatten the map, and perform the thing Dan said to do.
{:a {:b 1} :c 2} => {[:a :b] 1 [:c] 2}
you can use something like symbol-paths
from here: https://github.com/escherize/tracks/blob/master/src/tracks/core.cljc#L4
(require '[clojure.set :as set])
(defn ->key-paths
([x] (into {} (->key-paths x [])))
([x path]
(if (map? x)
(mapcat #(->key-paths (val %) (conj path (key %))) x)
{path x})))
;;(->key-paths {:a 1 :b 2 :c {:d {:e [3 4 5] :x 6}}})
;;;; => {[:a] 1, [:b] 2, [:c :d :e] [3 4 5], [:c :d :x] 6}
(defn subset? [a b]
(set/subset?
(set (->key-paths a))
(set (->key-paths b))))
(subset?
{:a 1 :b 2}
{:a 1 :b 2 :c {:d {:e [3 4 5] :x 6}}})
do you care about speed ? if not: (nil? (first (clojure.data/diff subm m)))
should work right ?
Nice! Thanks everyone who chipped in here 👍 I have a few paths to explore now 😃
(= (class (proxy [Throwable] [nil nil false false])) (class (proxy [Throwable] [nil nil false false])))
;;=> true
It seems proxy is somewhat smart and doesn't create duplicate anonymous classes?