Fork me on GitHub

I put a library in my dependencies and used :require to pull the library in. when I call to it inside my source code and evaluate it it works fine. but if i try to evaluate that exact same expression directly in my repl i'm getting a namespace error. do I have to pull in that library in the repl? why would I if it's already in my source and working there?


i'm using emacs w/ cider if that matters.


Code needs to be require'd into each namespace that needs to use it. Your REPL starts in the user namespace which won't have anything required in.


ahh ok. but why does it evaluate fine within my source file?


Because that namespace does require it.


ahh, but the repl doesn't put me right in that namespace? it puts me in user?


Correct. So another option is:

user=> (require '
user=> (in-ns '
nil> (csk/->snake_case "hi world")


You would still have to require your code's namespace (``) to load it, and then jump into that namespace -- and now it's just like you are in your source file's code.


ok, ok. or i just switched to the namespace with (ns and that worked as intended


which is the more idiomatic way to do this stuff?


Be careful. That won't work if you haven't already loaded (required) that namespace!


You'll create a new empty namespace instead.


ahh yes. ok, i see. yeah I had already had that code saved before starting the repl


this seems like it could get complicated if you for some reason are adding dependencies and working in the same session. what do folks normally do? save and restart the repl completely?


Hello people, what name you usually give to the base value of your reduce functions?


It depends on what it represents. Each case tends to be different.


(if I'm understanding your question correctly)


i always try to find a name that suits the function, but it's weird to read


@chase-lambert If you are just revising some saved code and want to load the changes, you can (require 'my-ns.core :reload)


@chase-lambert With Leiningen, if you add a dependency you generally have to restart the REPL. With Boot, you can add dependencies to REPL interactively. But dependencies are not namespaces, they're external libraries.


As @mfikes says, if you're just adding new namespaces, you can just require them, and require .. :reload other namespaces, as needed to (re)load your own code into the REPL.


thanks folks. not sure if this is related but now i'm trying to run this test and getting No test namespace:


@chase-lambert Are you trying to do (clojure.test/run-tests ' If so, have you required that namespace first?


to be honest, i'm winging it. the tutorial said to use lein test or follow your editor's instructions and i'm trying to do the latter so I learn cider.


So I think i just told cider to run the test while I was in that test file


lein test does work btw. I think I'm just going to have to learn more about the namespaces


Cider has a short cut 'C-c C-t p'. (read control c , control t, p) that will run all tests in your project


N instead of p for tests in the current namespace and t for the test at point


ok. i'm starting to figure it out. in the repl if i switch to the test file namespace i can run that run-tests command and it works.


when i just tried that shortcut of yours I get a different error so that's progress! haha


Says No assertions were run. Did you forget to use 'is' in your tests? but I did use 'is'


Maybe that means it wasn't reading my test file but just the main file I was in at that time which had no tests in it?


I don't know. I've kind of wasted my whole programming session on this unfortunately. should have just done the stupid lein test and moved on with the tutorial. lol. Anyways, thanks for the help folks!


Hi everyone, I have a project that I've been working on for a while and today when I started my repl it randomly gave me an error message that it's never done before. I haven't changed anything in my project. Any idea what could have caused this? I've tried lein clean but that hasn't fixed it. If I start a fresh project then I have no problem with getting the repl running.


@UA9399DFZ it seems like you're loading some image from the Internet in quote_image_maker.core$quotes_from_page invokeStatic core.clj 1354 Perhaps that image is no longer available?


You're right! Thanks, jumar. You saved me from a morning of pulling my hair out 🙂

👍 4

I'd had a local server running yesterday that isn't running today, and it was looking for a file on there.


Any idea why didn’t catch the enter key?


with other keys, works fine


I'm not sure what else could be wrong, but at least your if-clause needs to wrap the two bottom lists, right? EDIT: nvm I misread!


yes, I would like to catch the ENTER key.. but other keys.. like CTRL, SHIFT.. not works. I don’t know why.


I will try out with a pure div, maybe xterm thing..


could it be that .-key is not a number? according to you'd get "Enter" on an enter-click


I check it, thanks!


Ok, I ckecked.. that is something “xterm .. problem”.


I forget add tabIndex 0, that was the problem


Hey all, forgive me but... 😅 what is the up to date recommendation for creating REST (micro) services in Clojure? I’ve found answers mostly for several years back and I imagine things move quickly. Looking for something light - web server/URL-to-code mapping but not necessarily much more. New to Clojure, done a lot of Java/Python/etc.

Andrea Imparato13:10:15

I have the same question 😄. I think nowadays for rest api it's liberator vs yada mostly but I'm not an expert as I said 🙂


Hey, thanks. That’s more information than nothing 😀

frenata13:10:54 is probably worth checking out the options there personally I've used (and been happy with) compojure / compojure-api.

Andrea Imparato13:10:47

@U8RCW3A2Y how much did you have to add on your own before having a well structured web api application?


not too much, a jetty server to run the handler


Sorry missed out on this earlier @UCW3QKWKT


from a small prototype I'm working on lately:

(ns monitor.server
  (:require [monitor.handler :refer [handler]]
            [ring.adapter.jetty :refer [run-jetty]])

 (defn -main [& args]
   (let [port (Integer/parseInt "3005")]
     (run-jetty handler {:port port :join? false})))
where handler is a call to compojure.core/defroutes, is a fully functional microservice style server


Very cool, thank you for elaborating!

Nathaniel Stevens13:10:50

What’s the best way to kick off a bunch of threads and not continue execution until all threads are complete?


You could use a java.util.concurrent.CountDownLatch for that.


as long as you know how many threads you will be starting ahead of time.


Could also kick off a bunch of futures and (mapv deref futures)?


You would also benefit from the built-in ThreadPool (unless you want to have your own).

Nathaniel Stevens13:10:31

These are great suggestions!

Nathaniel Stevens13:10:41

How does mapv defer work?

Nathaniel Stevens13:10:41

I think defer may be cljs only? Is that right?


he typo'd deref


mapv is one way of forcing a lazy seq, but only because I can never remember the differences between doseq, doall etc.


if it helps, doseq is like for but for side effects (returns nil, allows multiple forms in its body, is eager), doall takes a lazy-seq and realizes it (but the output is still a lazy-seq and only the top level is forced), dorun forces each element of a lazy seq but it returns nil (thus doesn't use as much heap as doall and is strictly for side effects over a lazy input), run! is like map with two args, but returns nil (strictly for side effects)

Nathaniel Stevens14:10:21

Aha! Beautiful, that’s exactly what I’m looking for. Thanks guys!

Yehonathan Sharvit14:10:58

Is there a way to undefined an existing variable in Clojure?

Eric Scott17:10:19

I'm hoping someone can point me in the right direction here. Code that was working just fine last week has suddenly started complaining about a missing spec.alpha dependency. So I included it in my project( [org.clojure/clojure "1.9.0"][org.clojure/spec.alpha "0.2.176"]). Now when I enter lein run or lein repl I get an error, I think this is the relevant excerpt from the stack trace:

Eric Scott17:10:35

at clojure.lang.Compiler.load( ... 6 more Caused by: java.lang.IllegalStateException: Attempting to call unbound fn: #'clojure.core/ident? at clojure.lang.Var$Unbound.throwArity( at clojure.lang.AFn.invoke( at clojure.spec.alpha$spec_impl.invokeStatic(alpha.clj:915) I would appreciate any guidance in sorting this out. Thanks.


That almost sounds like something is loading an earlier version of Clojure. Are you using Leiningen @eric.d.scott?


Could you share your project.clj file? And also check ~/.lein/profiles.clj to see what's in there (if anything).


and give the results of *clojure-version* ( i think that's the dynamic var)

Eric Scott17:10:30

Ah! I changed this line in my ~/.lein/profiles.clj :

Eric Scott17:10:32

:dependencies [[org.clojure/clojure "1.9.0"]] ;;"1.8.0"]]

Eric Scott17:10:40

... and it fixed the problem

Eric Scott17:10:19

So do I gather from this that I must always set this to the highest clojure version used by any of my projects?

Eric Scott17:10:16

Is there a risk associated with using older clojure versions from projects started a while back?


what clojure version do you have specified in your project?

Eric Scott17:10:00

... as generated by the luminus template, I think


I dunno, I have never really used /.lein/profiles.clj because my use of lein largely predates it, and because of my lack of personal experience with it, all I have is questions like yours to go on, and of course it is always someone asking for help with a problem (people don't ask when things are going well), so given that bias I am of the opinion that anything but an empty /.lein/profiles.clj is asking for trouble


(and adding to the biased opinion, I have a pretty low opinion of everything people tend to stick in there)


I find it odd to specify a clojure dependency in .lein/profiles. Usually that is best for cross-project user-specific deps/plugins like formatters, linters, scope-capture, etc


And each project would define its own clojure dep in the project.clj/deps.edn/etc

Eric Scott17:10:23

Ah. I started this file months ago following some tutorial (Brave and True maybe?), and haven't thought about it since.


cross project user specific plugins are a fancy way to make your builds not repeatable


Depends on the profile/scope


I can’t remember a time where cljfmt in a dev profile plugin screwed my build


shrug the other week there was just a discussion about a popular plugin (ultra maybe?) and how it injects itself as a dependency of the project, which results in the project's generated pom having a dependency on it when you create an artifact


that kind of thing happens all the time, it is just mostly small enough that it gets ignored


ultra just happens to have about a billion deps so people notice


imo that’s a red flag on the plugin(s) that forcibly inject themselves as a dep, than a red flag on the utility of a global profiles


ultra is weird


But I agree that the more you can put into each project themselves is better, but I personally don’t want to keep a cljfmt plugin up to date for the occasional use across all my projects


Certainly commenting most things out of your /.lein/profiles.clj is a reasonable practice if you are having Leiningen dependency headaches, to see if they go away. That an 'lein clean'. I have only lein-ancient and eastwood in my /.lein/profiles.clj most of the time, and unlike ultra I haven't seen them cause any troubles.


also under-rated is making up new profile names specifically for a given plugin or dep


eg. :perf-profile or :disasemble


Regarding spec being a dependency, or a missing one, Clojure 1.8 doesn't implement or include spec unless you use a special back-ported library to add it. Clojure 1.9 depends on spec normally, so if you depend on Clojure 1.9 you should not also need to explicitly add dependences that it brings in for you. If you are doing some special generative testing things you may need additional dependencies, but not just for running Clojure normally.


@eric.d.scott ^^^ I meant to ping you on that.


it isn't that using .lein/profiles.clj is guaranteed to break your builds, it just is a source of potential differences for a dev team that isn't in source control

Eric Scott17:10:34

Ah. Good to know. Thanks.


~/.lein/profiles.clj seems to be a big source of beginner problems so it's usually the first thing I'm suspicious about when I see what looks like a dependency problem.

👍 8

Regarding your question "Is there a risk associated with using older clojure versions from projects started a while back?" not sure if the following ramblings answer your question -- Across different invocations of the JVM, I think people often have some projects using Clojure version A and others using Clojure version B. The different JVM runs don't affect each other, so whatever versions of Clojure libs they use is independent for each, and the only times they should matter is if those two JVM processes communicate or interact in some way that depends upon those libraries.


It is common to have multiple versions of Clojure installed on disk on the same machine at the same time, with no problems for that reason alone.

Eric Scott18:10:43

Yes that makes perfect sense now that I've removed profiles.clj from the mix. Somehow I got the impression from the tutorial I was using that profiles.clj was the norm.


With Leiningen, a project-specific project.clj file is the most common way to specify other libs that project uses.

Eric Scott18:10:54

Yes I see that now. Thanks for everyone's help!