Fork me on GitHub
quan xing11:08:02

m1 {:a 1 :c 2 :d 3} m2 {:a 2 :c 2 :d 3} I want to get the right of the different value map in two maps {:a2} Is there any embed function to find it in the Clojure?

Martin Půda12:08:24

(clojure.set/difference (set {:a 2 :c 2 :d 3})
                        (set {:a 1 :c 2 :d 3}))
=> #{[:a 2]}


I might break down the reasoning a little here. Maps are made of MapEntrys, which are key-val pairs. Using set or anything that coerces a map into a collection returns a sequence of key-val pairs. In clojure, equality on structures is automatically calculated (anonymous functions excepted). So clojure.set/difference finds any elements of m2 that don't appear in m1. The MapEntry [:a 2] doesn't appear in m1.



Ben Sless13:08:35

@U24QP2D4J in Clojure the maps are flattened and the entries are created only if you iterate on them as a sequence, on demand, to avoid indirection

👍 1

Is there a way to tap> clojure tests output, to say make it go to portal for viewing diffs?


Should be a way: • some for clojure.test • the default version of So I think you could do something like

(defmethod report :fail [m]
  (tap> {:expected (:expected m)
         :actual (:actual m)})
    (inc-report-counter :fail)
    (println "\nFAIL in" (testing-vars-str m))
    (when (seq *testing-contexts*) (println (testing-contexts-str)))
    (when-let [message (:message m)] (println message))
    (println "expected:" (pr-str (:expected m)))
    (println "  actual:" (pr-str (:actual m)))))

R.A. Porter16:08:35

As you've specifically mentioned Portal, you can follow this guide -


i figured someone did this, but wasn't finding it. thanks.


@joel380 if you want a generic hook, look at the dynamic var clojure.test/report


and read the docstring of the clojure.test namespace


you can use that to intercept and tap>

Ben Lieberman20:08:56

I have some stubbed Java code that I pointed to in my project.clj by using the :java-source-paths key. I was able to successfully compile this code and it is now in the target folder as I expect. But it was not added to my classpath. I expected this to occur bc the docstring for lein javac says it is like using the javac -cp command. What did I do wrong? And is it enough to manually concatenate the directory location of the .class files onto my classpath, or is there a better way?


hard to say. what do you mean by "it was not added to my classpath"

Ben Lieberman20:08:40

Calling lein classpath shows that the dependencies from Maven were added. But not the Java code from :java-source-paths. I get a ClassNotFoundException when I try to import any of the code from the files


you don't need java source on the classpath


so there is no reason for :java-source-paths to be part of the classpath


a wild guess, what package is your java code in?

Ben Lieberman20:08:01

What about the resulting .class files though? I know very little about Java unfortunately but I was under the impression that in order for the class loader to find any compiled code it would have to be in the classpath


the files themselves don't go on the classpath, the files go in a directory tree that matches their package structure, and the root of that directory tree goes on the classpath


if the java code doesn't explicitly declare a package, it goes in the default package, which, uh, I don't entirely recall because it doesn't come up often, but it can cause issues. and if you are inexperienced with java you might leave out a package declaration, which might land you here, but that is me wildly jumping ahead of things

Ben Lieberman20:08:16

the package is but I tried [:import SessionBuilder] in my ns and that still threw a ClassNotFoundException


is the classnotfoundexception for SessionBuilder, or for some class SessionBuilder depends on?

Ben Lieberman20:08:46

it's for

Ben Lieberman20:08:20

all the .class files are in my project root /target


oh, you are just typing [:import SessionBuilder] into the repl?


yeah, that for sure doesn't work

Ben Lieberman20:08:49

no in my core.clj and then doing cider-eval-buffer


you need some more () or []

Ben Lieberman20:08:50

so it should be (ns blah [:import thing [SessionBuilder]])


that is being interpretered as a class with the full name and a class with the full name SessionBuilder


( ...) where the ... is potentially more classes in the same package

Ben Lieberman20:08:25

got it working, thanks! it ended up being .demo.SessionBuilder


user=> (import 'java.util.concurrent.LinkedBlockingQueue)
user=> LinkedBlockingQueue
user=> (import '(java.util.concurrent LinkedBlockingQueue ArrayBlockingQueue))
user=> LinkedBlockingQueue
user=> ArrayBlockingQueue

👌 1

Is it accurate to describe all relationships between dependencies ->> dependants as a library -> client relationships, or is there some nuance to it? Are there some deps that aren't libraries? Are some users of dependencies not clients? Is there better jargon to use here?