This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-05
Channels
- # announcements (1)
- # babashka (16)
- # beginners (36)
- # biff (1)
- # calva (2)
- # cider (4)
- # cljdoc (1)
- # clojure (118)
- # clojure-austin (2)
- # clojure-czech (2)
- # clojure-europe (19)
- # clojure-norway (3)
- # clojure-spec (8)
- # clojure-uk (3)
- # clojurescript (11)
- # conjure (1)
- # cursive (3)
- # datalevin (5)
- # datomic (7)
- # emacs (16)
- # events (1)
- # figwheel-main (3)
- # fulcro (5)
- # hyperfiddle (17)
- # jobs (2)
- # lsp (19)
- # malli (5)
- # nbb (10)
- # off-topic (5)
- # polylith (5)
- # re-frame (3)
- # reagent (11)
- # remote-jobs (2)
- # shadow-cljs (1)
- # spacemacs (7)
- # web-security (4)
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?
(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 MapEntry
s, 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.
@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
Is there a way to tap> clojure tests output, to say make it go to portal for viewing diffs?
Should be a way: • some https://clojure.github.io/clojure/clojure.test-api.html for clojure.test • the default version of https://github.com/clojure/clojure/blob/4b9eadccce2aaf97e64bcc8e35c05c529df8fdd2/src/clj/clojure/test.clj#L375 So I think you could do something like
(defmethod report :fail [m]
(tap> {:expected (:expected m)
:actual (:actual m)})
(with-test-out
(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)))))
As you've specifically mentioned Portal, you can follow this guide - https://github.com/djblue/portal/blob/master/doc/guides/test-runner.md
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?
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
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
the package is com.ibm.mq.demo
but I tried [:import com.ibm.mq.demo SessionBuilder]
in my ns and that still threw a ClassNotFoundException
is the classnotfoundexception for SessionBuilder, or for some class SessionBuilder depends on?
it's for com.ibm.mq.demo
all the .class
files are in my project root /target
no in my core.clj
and then doing cider-eval-buffer
so it should be (ns blah [:import thing [SessionBuilder]])
that is being interpretered as a class with the full name com.ibm.mq.demo and a class with the full name SessionBuilder
(package.name class.name ...) where the ... is potentially more classes in the same package
got it working, thanks! it ended up being
user=> (import 'java.util.concurrent.LinkedBlockingQueue)
java.util.concurrent.LinkedBlockingQueue
user=> LinkedBlockingQueue
java.util.concurrent.LinkedBlockingQueue
user=> (import '(java.util.concurrent LinkedBlockingQueue ArrayBlockingQueue))
java.util.concurrent.ArrayBlockingQueue
user=> LinkedBlockingQueue
java.util.concurrent.LinkedBlockingQueue
user=> ArrayBlockingQueue
java.util.concurrent.ArrayBlockingQueue
user=>