Fork me on GitHub
#beginners
<
2022-03-24
>
Yunzhou05:03:06

Hi all, I’m using Calva and working on a Leiningen project. I have a repl running, and then decide to add a new dependency. After I do lein install, how do I get the repl to load the new dependency? I’ve tried “Calva: Refresh All Namespaces”, “Calva: Load Current File and Dependencies”, still I’m getting “Unable to resolve symbol”. Thank you.

pez06:03:23

You will either need to restart the REPL and reconnect to it. Or, if Leiningen has some dynamic loading mechanism, you can use that and then Load Current File should do the trick. Or just (require 'the-new-lib.some-ns) to try it out.

🙌 1
Yunzhou06:03:10

alright, will try that, thanks!

🙏 1
pez06:03:58

For completeness. For people using #tools-deps, there is a branch . With a function add-lib that will let you dynamically add dependencies. An earlier version of it is described here: https://insideclojure.org/2018/05/04/add-lib/ (I think the API has stayed the same.)

👍 1
practicalli-johnny13:03:10

FYI, the Clojure CLI deps.edn function is now called add-libs and can load multiple libraries into a running REPL process. Examples: https://practical.li/clojure/alternative-tools/clojure-cli/hotload-libraries-editor.html

Yunzhou01:03:13

cool, thank you, so it seems like a limitation of Leiningen in this case?

pez05:03:19

A ”limitation” it shares with tools-deps.

pez05:03:36

I think that with Leiningen most people solve the hot loading of dependencies using Pomegranate: https://github.com/clj-commons/pomegranate

practicalli-johnny09:03:03

Actually it's a constraint of the underlying Java host platform, for which there are tools in the Clojure community to mitigate. I really only do hotloading of libraries when working in unfamiliarity domains, or specifically trying out libraries that are new to me. I've never found it an issue to simply restart the REPL, it only takes a second or two. Specific application states can be set using code in rich comment blocks if required

pez09:03:52

I find huge issues with restarting my REPLs. That's brutal! I go the other way and use the add-lib branch as often as I get away with it.

pez10:03:44

btw, @U05254DQM. In your add-lib guide it is quite hard to understand that you need a special version of tools.deps.alpha. The information about this is there, but probably should be more prominently placed.

practicalli-johnny10:03:25

setup of the alias in in the previous page, https://practical.li/clojure/alternative-tools/clojure-cli/hotload-libraries.html I'll add a link to make it more obvious

pez10:03:06

Awesome: I think it should be mentioned that a special version is needed right in the start, where it now reads: > The add-libs function from clojure.tools.deps.alpha avoids the need to restart the REPL when adding a new library to a project. And those tabs for how to do it made it a bit hard for me to see the it was two options for adding the dependency. Maybe because it speaks about an alias and not a dependency. But also because I'm not used to tabs in an article.

practicalli-johnny12:03:06

In-page tabs are used liberally through the book where I offer alternatives. The default tab is always the recommended approach the book follows. Sorry you find it difficult to use, but I haven't found a more appropriate way of offering alternatives on the same page without drowning people in extraneous information. I could remove the alternatives, which would mean less work for me, but possibly offer less value.

pez12:03:23

I like the alternatives, and that they don't take up space. I think that when you read the book you will probably quickly learn what the tabs are. But many people, like me, will arrive via some link to check a specific thing out. I think maybe all that I would need is some help to quickly understand the context and my options. Something like so, maybe?

leifericf08:03:17

Here are a few more thoughts from my entry into the world of Clojure.

lightsaber 5
Pratik14:03:52

Couldn’t find a sub for that, so posting this question here, I am using https://github.com/clj-commons/camel-snake-kebab library for string conversions and but I want to treat number as a single thing rather than treating it as an upper case later, for example,

(csk/->kebab-case-keyword :s2_id)
Should return s2-id rather than s-2-id . Is there any way we could do that?

Ferdinand Beyer15:03:44

Try:

(csk/->kebab-case-keyword :s2_id :separator \_)
; => :s2-id
Note that a super similar example is prominently https://clj-commons.org/camel-snake-kebab/:
(csk/->snake_case :s3-key :separator \-)
; => :s3_key

Roee Mazor14:03:25

Hi, I have an existing http-kit - compojure server and I want to send over one of the endpoints a byte array, i am getting this error:

No implementation of method: :as-response of protocol: #'liberator.representation/Representation found for class: [B%
what is the right way to do this? (assuming I don’t want to slurp and then convert the string to bytes on the other side)

Roee Mazor16:03:49

(ByteArrayInputStream. my-byte-array) worked perfectly 🙂

🙏 1
Nom Nom Mousse14:03:45

How do I spec a 2-tuple (vector) where the first entry is a keyword and the second is a map?

Nom Nom Mousse14:03:10

I see coll-of, but that does not consider order or length.

flowthing14:03:56

clojure.spec.alpha/tuple?

Nom Nom Mousse14:03:52

I'll try. I looked for s/vec.

Nom Nom Mousse14:03:01

Yup: (s/conform (s/tuple int? int?) [1 2]) I did not think to look for tuple since I thought it did not exist in Clojure, but that we use vec for the same purpose.

Ferdinand Beyer14:03:56

I recommend checking out the official spec guide, which includes examples for tuple: https://clojure.org/guides/spec

🙏 1
mesota16:03:22

Hello Clojurians, newbie here. Any opensource re-frame project you recommend for studying? Ideally, it would be an SPA with the kind of complexity found in typical full fledged web applications. Thanks!

JoshLemer17:03:54

Not an open source project per se, but Web Development with Clojure walks you through step by step the how and why of creating a production grade (-ish) full, SPA+back end in clojure https://pragprog.com/titles/dswdcloj3/web-development-with-clojure-third-edition/ It's also reasonably up to date, with the latest edition having been released this past summer

mesota17:03:44

Thanks a lot @UEH6VEQQJ!

❤️ 1