Fork me on GitHub

Using Calva and VSCode, is it possible to require things in the REPL? I’ve tried (:require my-projet.utils :as utils) but I get ; Syntax error (ClassNotFoundException)

Bart Kleijngeld08:09:57

Try: (require '[my-project.utils :as utils])


Ah that’s great, thanks

👍 1
Bart Kleijngeld08:09:57

The :require keyword is part of the ns declaration, that's what probably got you confused. I recommend reading up a little about namespaces and the REPL basics 🙂


FYI, there is nothing special about Calva's REPL. I know it can seem like that and you don't know how all these things compose. But regard Calva's REPL as if it is a regular Clojure REPL. That mental model will take you far. And when you are ready to challenge that model, then, well, then you will be ready. 😃

👍 1

Check 🙂 Won’t include that info in the future then


Oh, it is often worth including. There are some side effects to how the REPL is wired that can be involved in a particular problem. But it is also good to know that the regular Clojure reality applies. Calva connects to an nREPL server running in the same process as your application and the Clojure REPL. The nREPL server takes requests from Calva and uses the Clojure REPL to evaluate, then packages the results in a response and gives it to Calva. Meaning that the forms you evaluate using Calva will be evaluated by the Clojure REPL. Meaning that a syntax error like the one in the thread start, comes directly from the horse's mouth.


I see, thanks for the info 🙂


You are welcome 😃 And welcome to #calva !


I should avoid putting anything in deps.edn's :extra-paths that isn't meant to be evaluated?


Can you give an example?


Say I have some clojure files which I don't want to run, but just want to count the number of lines in them. Is it safe/make any sense to put those in :extra-paths?

Alex Miller (Clojure team)12:09:11

You don't need to put them in :extra-paths to read them

Alex Miller (Clojure team)12:09:36

But doing so will not automatically cause them to be evaluated

Alex Miller (Clojure team)12:09:38

There are some tools (like tools.namespace) that may load all of the namespaces on the classpath, but whether that affects you depends on tooling


I found that if I include a particular Clojure repo in :extra-paths, unit tests which throw an exception stop working in my particular tooling setup :thinking_face:

Alex Miller (Clojure team)12:09:16

Hard to explain without more info. I have seen someone here that ran into a similar issue due to use of tools.namespace but don't remember the details


Yes, it would be easier to help you if we had a reproducible case.


I can't reproduce in the REPL so I'm guessing it's got something to do with how my editor runs the tests. Thanks for your input @U064X3EF3 and @UEQPKG7HQ.

👍 1

I created an issue about it in the cider-nrepl repo and apparently in this case it does matter that there is "correct code" on the classpath. Just wanted to leave the link/details here in case anyone stumbles across it in the future.

🙏 1
Joseph Graham11:09:19

Hi all. Trying to optimise this with threading but I can't because a string is not a function: (Integer/parseInt ((request :query-params) "id")) Tried optimizing it to this: (-> request :query-params "id" Integer/parseInt)

Bart Kleijngeld11:09:43

Before jumping in how to go about it, I would ask myself, critically, if a threading version would really be more readable. I doubt that personally. Can you explain what you dislike about your initial expression, and why you like to use threading here?

Mario Trost11:09:52

(macroexpand '(-> request

(. Integer parseInt ("id" (:query-params request)))

Joseph Graham11:09:24

Thanks Mario that shows why it doesn't work


Use parentheses. The trick with leaving them out only works for a few built-in Clojure data literals since they implement IFn, i.e. not strings and Java methods.

👍 1
Mario Trost11:09:24

What @U03BYUDJLJF said 👆 If it is just for an exercise, I like macroexpand to show me what the threading macro is doing.

👍 1
Joseph Graham11:09:02

Alright thanks all.


As of clojure 1.11 you can use parse-long instead of Integer/parseInt, which does behave better in a threading macro.

(some-> request
        (get "id")
This ☝️ looks perfectly ok to me and I like it better than (parse-long ((:query-params request) "id")) It tells you how to get the parameter "id" by listing the steps you have to do, in order, and doesn't throw an exception if query-params doesn't contain the key "id".

😃 1
🙏 1
👍 1
Joseph Graham13:09:23

wow, thanks. I like it!


I want to replicate this behavior (ruby) @data.xpath("//E1EDP01[not(ABGRU) or ABGRU = '99'][not(PSTYV = 'TATX')]") in clojure. So far I have (xml-> xml :IDOC :E1EDP01) but I’m unsure how to do the not statements. Does anyone know?


It’s taken from [ :refer [attr text xml-> xml1->]]


Oh, ok, I'm not familiar with the library but maybe you can use (complement text=)


Ok so this returns rows that has the ABGRU tag (xml-> xml :IDOC :E1EDP01 [(tag= :ABGRU)])


Now I just need to negate that


I tried using complement, but I can’t get it to work


(tag= :ABGRU) returns a function


are you sure (complement (tag= :ABGRU)) doesn't work?


this: (xml-> xml :IDOC :E1EDP01 [(complement (tag= :ABGRU))])


I have two E1EDP01 blocks, one that includes the ABGRU tag and one that doesn’t. Sorry to say but the last piece doesn’t seem to yield the block without the tag, it returns an empty array


I don't know what's going on and this problem seems specific to that library, so maybe check out #xml .


I’ll try there, thanks anyway for your time 🙂


Did you find a solution after all, @U033Q6RBXJ6?



(xml-> xml :IDOC :E1EDP01
                    (fn [loc]
                      (and (or
                            (some #(and (= :ABGRU (:tag (zip/node %)))
                                        (= "99" (text %)))
                                  ( loc))
                            (not-any? #(= :ABGRU (:tag (zip/node %)))
                                      ( loc)))
                           (not-any? #(and (= :PSTYV (:tag (zip/node %)))
                                           (= "TATX" (text %)))
                                     ( loc)))))

👍 1

that's good to hear 🙂

Jim Strieter22:09:03

When using tools.cli, how do you tell Clojure that a parameter is supposed to be a string? My cli-options vector has this:

(def cli-options


You need "--id-str ID" -- you have to provide a named placeholder for value-based options. See the example in the Quick Start where -p/--port is a value option and -v/-h are flag options.