Fork me on GitHub
#beginners
<
2022-07-15
>
Ivan Koz05:07:38

Is it possible to de-structure namespaced keywords like {:profile/id 123 :profile/name "abc"}

lsenjov05:07:59

(let [{:profile/keys [id name]} data] ...)

☝️ 3
pavlosmelissinos05:07:00

Checkout also the destructuring guide for some additional information: https://clojure.org/guides/destructuring The Namespaced keywords section in particular

Ivan Koz05:07:29

whoa, i've looked that document before and missed it, ty

Bart Kleijngeld12:07:06

I'm going to write my first unit tests for a project, and I was looking for some inspiration. The core clojure.test library seems fine, but perhaps I'd be missing out (I also like pytest way better than Python's core unittest library 😉). Any tips/experiences?

Bart Kleijngeld12:07:04

I've also heard positive stories about https://github.com/marick/Midje.

lispyclouds13:07:32

What sort of things are you missing in clojure.test? Often clojure is much more extensible than you think if you feel something is missing 😉

delaguardo13:07:03

If you are a beginner give clojure.test a try. It is good enough to begin with and only when (or if 😉) you hit some problems — look at another helpers

lispyclouds13:07:46

Midje has quite the mixed feelings here in the community and I'd also recommend start off with clojure.test and see whats missing

Bart Kleijngeld13:07:36

I'm unfamiliar with both (all) options, so I'm not missing something, but was curious what place was best to start. Sounds like giving clojure.test a try is a good way then. Thanks 🙂

👍 2
1
genmeblog13:07:32

You may also use https://github.com/clojure-expectations/clojure-test as a clojure.test extension in case you miss something.

gratitude 1
Benjamin15:07:00

Can't load library: /usr/lib/jvm/java-17-openjdk/lib/libawt_xawt.so
do you know why cider middleware tries to load this and it is not there? Works when I don't manually set the jdk path to opendjk 17

1
Benjamin15:07:56

Can't load library: /usr/lib/jvm/java-17-openjdk/lib/libawt_xawt.so
ERROR: Unhandled REPL handler exception processing message {:op stacktrace, :nrepl.middleware.print/stream? 1, :nrepl.middleware.print/print cider.nrepl.pprint/pprint, :nrepl.middleware.print/quota 1048576, :nrepl.middleware.print/buffer-size 4096, :nrepl.middleware.print/options {:right-margin 70}, :session 8e0cd955-f748-4dc5-a446-fefdff3d06da, :id 445}
java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: Could not initialize class java.awt.image.ColorModel
	at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
	at clojure.core$deref_future.invokeStatic(core.clj:2317)
	at clojure.core$future_call$reify__8544.deref(core.clj:7041)
	at clojure.core$deref.invokeStatic(core.clj:2337)
	at clojure.core$pmap$step__8557$fn__8561.invoke(core.clj:7092)
	at clojure.lang.LazySeq.sval(LazySeq.java:42)
	at clojure.lang.LazySeq.seq(LazySeq.java:51)
	at clojure.lang.RT.seq(RT.java:535)
	at clojure.core$seq__5467.invokeStatic(core.clj:139)
	at clojure.core$map$fn__5939.invoke(core.clj:2774)
	at clojure.lang.LazySeq.sval(LazySeq.java:42)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class java.awt.image.ColorModel
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:467)
	at clojure.lang.RT.classForName(RT.java:2209)
	at clojure.lang.RT.classForName(RT.java:2218)
	at clojure.lang.Compiler.maybeResolveIn(Compiler.java:7455)
	at clojure.core$ns_resolve.invokeStatic(core.clj:4371)ERROR: Unhandled REPL handler exception processing message {:op eldoc, :ns user, :sym java.awt.image.ColorModel, :session 8e0cd955-f748-4dc5-a446-fefdff3d06da, :id 451}
java.lang.NoClassDefFoundError: Could not initialize class java.awt.image.ColorModel

Benjamin15:07:22

I mention cider because it seems to throw inside the nrpel handlerr

Benjamin15:07:07

nvm when I run without nrpel I get the same error. First clj start like usual, then I eval (require '[nextjournal.clerk :as clerk])

Execution error (UnsatisfiedLinkError) at java.lang.ClassLoader/loadLibrary (ClassLoader.java:2393).
Can't load library: /usr/lib/jvm/java-17-openjdk/lib/libawt_xawt.so
also this file does not exist at that location. Maybe I just need to install libaws_xawt

Benjamin15:07:04

ah I'm almost certain it is because I have jre17-openjdk-headless but I should use not headless to use clerk

Benjamin15:07:08

can confirm installing jre17-openjdk fixed my issue

🍺 1
chromalchemy19:07:18

What is the basic way to to run functions sequentially, but have the values available for subsequent functions? Like a do-> thread..? I am trying to tie together api I/O functions, where there is some latency for results. (I guess this falls into async territory?) kind of like this:

(let [new-item-name "name"]
  (create-item! new-item-name)
  (let [new-item (get-item item-name)] ; with system-supplied id
    (update-item! (:id new-item))))

Ivan Koz19:07:33

could you rephrase your question? Not sure what you are asking, did you mean

(let [new-item-name "name"
      new-item (create-item! new-item-name)]
     (update-item! (:id new-item)))

chromalchemy19:07:08

Yes. That is simpler. But do the let bindings resolve before the body runs? create-item! and update-item! have network latency.

chromalchemy19:07:19

I guess in this case the update-item! latency doesn’t impact the function.

chromalchemy20:07:20

I’m sorry, no, create-item! and get-item are separate. Because when an item is created, is is supplied with a unique :id from the system. So I need to “create”, and then “get” a particular entity, before I can “update” it (via it’s :id )

Benjamin08:07:00

(let [new-item-name "name"
      ;; assuming create-item! runs blocking and has the side effect of creating an item
      _ (create-item! new-item-name)
      new-item (get-item item-name)]
  (update-item! (:id new-item)))
Like this everything runs sequentially. It doesn't matter if any of those calls are doing long running io. (same as your code but I put everything into a single let)

chromalchemy20:07:03

Ok, Thanks for the clarification