This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-10
Channels
- # 100-days-of-code (2)
- # announcements (2)
- # aws (11)
- # beginners (114)
- # boot (6)
- # calva (11)
- # cider (11)
- # cljdoc (2)
- # cljs-dev (7)
- # clojure (126)
- # clojure-berlin (1)
- # clojure-conj (4)
- # clojure-dev (1)
- # clojure-germany (12)
- # clojure-italy (22)
- # clojure-spec (96)
- # clojure-uk (111)
- # clojurescript (27)
- # core-async (8)
- # cursive (17)
- # datomic (26)
- # devops (5)
- # editors (15)
- # emacs (13)
- # events (1)
- # figwheel-main (27)
- # fulcro (64)
- # hyperfiddle (29)
- # jobs (8)
- # jobs-discuss (7)
- # liberator (4)
- # off-topic (46)
- # om (9)
- # onyx (1)
- # overtone (1)
- # perun (8)
- # re-frame (28)
- # reagent (35)
- # reitit (5)
- # shadow-cljs (96)
- # spacemacs (1)
- # testing (10)
- # timbre (8)
- # tools-deps (63)
- # unrepl (1)
- # yada (10)
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?
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.
Because that namespace does require it.
Correct. So another option is:
user=> (require 'serpent-talk.talk)
nil
user=> (in-ns 'serpent-talk.talk)
nil
serpent-talk.talk=> (csk/->snake_case "hi world")
...
You would still have to require your code's namespace (`serpent-talk.talk`) 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 serpant-talk.talk) and that worked as intended
Be careful. That won't work if you haven't already loaded (required) that namespace!
You'll create a new empty namespace instead.
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: serpent-talk.talk-test
@chase-lambert Are you trying to do (clojure.test/run-tests 'serpent-talk.talk-test)
? 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.
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
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?
https://pastebin.com/9XQ2JV1s
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?
I'd had a local server running yesterday that isn't running today, and it was looking for a file on there.
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.
could it be that .-key is not a number? according to https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values you'd get "Enter" on an enter-click
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.
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 🙂
https://github.com/razum2um/awesome-clojure#restful-api is probably worth checking out the options there personally I've used (and been happy with) compojure / compojure-api.
@U8RCW3A2Y how much did you have to add on your own before having a well structured web api application?
@U8RCW3A2Y Explain :)
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]])
(:gen-class))
(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 serverWhat’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.
You would also benefit from the built-in ThreadPool (unless you want to have your own).
These are great suggestions!
How does mapv defer work?
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)
Aha! Beautiful, that’s exactly what I’m looking for. Thanks guys!
Is there a way to undefined an existing variable in Clojure?
@moxaj thanks a lot
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:
at clojure.lang.Compiler.load(Compiler.java:7379) ... 6 more Caused by: java.lang.IllegalStateException: Attempting to call unbound fn: #'clojure.core/ident? at clojure.lang.Var$Unbound.throwArity(Var.java:43) at clojure.lang.AFn.invoke(AFn.java:32) 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?
Yes I am
Could you share your project.clj
file? And also check ~/.lein/profiles.clj
to see what's in there (if anything).
Ah! I changed this line in my ~/.lein/profiles.clj :
:dependencies [[org.clojure/clojure "1.9.0"]] ;;"1.8.0"]]
... and it fixed the problem
So do I gather from this that I must always set this to the highest clojure version used by any of my projects?
Is there a risk associated with using older clojure versions from projects started a while back?
1.9.0
... 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
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
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
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
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.
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.
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.
Yes I see that now. Thanks for everyone's help!