Fork me on GitHub
#beginners
<
2022-01-25
>
mbjarland08:01:59

is there some idiomatic way, other than read-string , of grabbing an artifact version out of a deps.edn file? I need this on the command line from a bash script and I can do the read-string call via a call to clojure with appropriate code snippet. Was perhaps hoping there would be something built in to say tools.deps to accomplish this?

Ben Sless08:01:06

Maybe a tool like #jet or cq?

mbjarland08:01:20

right, yes, that would work but this is part of a build process checked into a git repo and I was hoping to not have to install additional binaries on the building server...so if possible I'm looking for a clojure solution, clojure deps are ok as they can be auto-downloaded, but would prefer to stay away from system binaries

mbjarland08:01:56

ok digging into tools.deps...seems there are functions in there that might do this

oly14:01:05

I have a test which is comparing 2 maps when I run the test I get this result which I don't understand as that looks the same, I have done an external diff and both maps seem to be identical but I still see the test fail with the below diff. anyone got any pointers ?

diff: - nil          
          + nil            

oly14:01:31

The maps are nested so maps in maps and vectors as key values they also have time and uuid literals like these #time/instant "2019-06-05T08:48:45Z"

oly14:01:06

If i intentionally change the maps the diff shows the correct keys as different, I have done similar tests before and not encountered this behaviour

pavlosmelissinos14:01:21

Another question about map comparisons! How would you approximately compare two maps based on some epsilon value, e.g.:

(let [m1  {:a    46.042
           :name "Jim"}
      m2  {:a    45.041
           :name "Jim"}
      eps 0.005]
 (approx= m1 m2 eps))
;;=> true
the maps could be arbitrarily nested I suppose I could walk over the map and use something like https://github.com/clojure/algo.generic/blob/48f3894155abbc14835213281d01355af683b47a/src/main/clojure/clojure/algo/generic/math_functions.clj#L208-L212 for numbers and clojure.core/= for other non-collection types but I'm not sure it's the right approach, it feels kinda wrong. How do people usually solve this?

Alex Miller (Clojure team)14:01:12

you could use https://clojuredocs.org/clojure.data/diff to pull a list of differences and then compare only those

πŸ’‘ 1
πŸ™ 1
oly14:01:42

I did actually try that I get back nil nil and the map as the 3rd parameter, which I believe means no differences if the first and second value are both nil

oly14:01:05

I just went down the route of dissocing keys to find the key but its a key with a vector of maps which only contain strings or integers so nothing esoteric

Alex Miller (Clojure team)14:01:27

sorry, I was actually replying to @pavlos’s question :)

oly15:01:09

ah no worries, I guess we are looking at similar things

Alex Miller (Clojure team)15:01:30

any chance you have a nil value and programatically constructed symbol with the value nil?

Alex Miller (Clojure team)15:01:25

^^ bad, but possible :)

oly15:01:59

Fail in t

expected: {:id 6,
           :merchant_id 2,
           :billing_period 2,
           :name "Deactivated Feed",
           :feed_type_id 2}

  actual: {:id 6,          
           :merchant_id 2,
           :billing_period 2,
           :name "Deactivated Feed",
           :feed_type_id 2}
    diff: - nil          
          + nil            
I have drilled into the hashmap to get at this sub map which is failing

oly15:01:45

just going to start disocing from that I guess until it passes

oly15:01:32

Fail in t

expected: {}

  actual: {}          
    diff: - nil          
          + nil            
Even more confused now no key values left and it still fails 😞

ghadi15:01:19

do you have some sort of testing facility/pretty-printer?

oly15:01:42

got it different types I wrapped in type fn and all became clear thanks for your duckie πŸ™‚

ghadi15:01:41

not sure I understand -- can you elaborate?

oly15:01:17

so one is a clojure.lang.PersistentArrayMap the other is a postgres instance which happens to display as a hashmap when displaying

ghadi15:01:04

what is the class of the Postgres instance?

Benjamin15:01:08

is there an easy way to load all files in a jar (use case is to not restart repl)?

oly15:01:56

so I am using a library called toucan which creates a class per table/model

nonrecursive19:01:25

@oliver.marks I think I've sometimes seen that when the values you're comparing are a map and a record

nonrecursive19:01:58

(defrecord Foo [foo])
(deftest foo-test
  (is (= (map->Foo {:foo "foo"}) {:foo "foo"})))

nonrecursive19:01:34

looks like you got a handle on it though πŸ™‚

oly08:01:25

yeah be nice if the diff could report that kind of difference the amount of lost time trying to nail down the issue :p

Volodymyr Anokhin21:01:36

Hi. I try to instantiate class javax.jms.ServerSessionPool that has no ctor and get

Execution error (ClassCastException) at aq-test.consumer/receive-msg (consumer.clj:11).
class java.lang.Class cannot be cast to class javax.jms.ServerSessionPool (java.lang.Class is in module java.base of loader 'bootstrap'; javax.jms.ServerSessionPool is in unnamed module of loader 'app')
Parts of my code that are related:
(ns aq-test.consumer
  (:import [javax.jms ServerSessionPool]))
...
(let  consumer-instance [(.createConnectionConsumer connection queue "JMSPriority BETWEEN 3 AND 7", ServerSessionPool, 1000)] ;; <-- Failing here
Any hints how to proceed?

ghadi21:01:22

the code is passing a class instead of an instance of the class

Volodymyr Anokhin21:01:16

yup -- and if I change it to (ServerSessionPool.) I get

Syntax error (IllegalArgumentException) compiling new at (/tmp/form-init8842840836338661175.clj:1:215).
No matching ctor found for interface javax.jms.ServerSessionPool

Volodymyr Anokhin21:01:22

This ServerSessionPool thing seems not having any constructors

Volodymyr Anokhin21:01:16

yup -- and if I change it to (ServerSessionPool.) I get

Syntax error (IllegalArgumentException) compiling new at (/tmp/form-init8842840836338661175.clj:1:215).
No matching ctor found for interface javax.jms.ServerSessionPool

ghadi21:01:05

don't guess

ghadi21:01:26

check out the docs for ServerSessionPool and call the constructor you need

ghadi21:01:07

it might not even have a public constructor; might get one from some static factory method somewhere (I don't know)

ghadi21:01:20

it's an interface, so it might come from the JMS concrete backend library that you are using

ghadi21:01:36

e.g. ActiveMQ or whatever

Volodymyr Anokhin21:01:02

Oh, so additionally the implementation may be needed? I didn't thought of that. Thanks!

ghadi21:01:25

no problem. sorry I don't have more specific details

πŸ™Œ 1
Nundrum22:01:37

Where is the config file for clj so I can put this mess in it? It doesn't make any sense to put it in every project's deps.edn, but I can't find docs about any other config. {:deps {cider/cider-nrepl {:mvn/version "0.27.3"} }}' -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]"

dpsutton22:01:42

put this in .clojure/deps.edn

πŸ‘ 2
dpsutton22:01:46

{:aliases
 {:cider/nrepl
  {:extra-deps {nrepl/nrepl {:mvn/version "0.9.0-beta3"}
                cider/cider-nrepl {:mvn/version "0.27.2"}}
   :main-opts ["-m" "nrepl.cmdline"
               "--middleware" "[cider.nrepl/cider-middleware]"]}}}

Nundrum22:01:32

Who can I bug to get that on this page? https://clojure.org/guides/deps_and_cli

dpsutton22:01:35

in the reference

Nundrum22:01:48

But ~/.clojure/deps.edn isn't mentioned there

andy.fingerhut22:01:45

Under the heading "Operation" you can find this line: User - cross-project configuration (typically tools), usually found atΒ `~/.clojure/deps.edn`

Nundrum23:01:16

brilliant, thanks!

dpsutton23:01:22

@U02UHTG2YH5 you are right. I totally sent the wrong link. I glanced quickly before doing a little meeting and it looked like the right thing. Sorry about that

Nundrum00:01:58

No worries. Just concerned for my eyes for a minute πŸ™‚

practicalli-johnny13:01:11

You may find this user level configuration interesting, it has lots of examples of aliases for tools, libraries and middleware like Cider https://github.com/practicalli/clojure-deps-edn

πŸ‘ 1
Nundrum14:01:15

That is a very useful reference. Thank you!

πŸ‘ 1