Fork me on GitHub

In a project using compojure-api, I need to expose a POST endpoint taking some unsigned long params:

(POST "/update" []
      :return Boolean
      [size-identifier :- Byte
       firmware-version :- String
       packet-size :- Long    ;Should be unsigned long
       arr :- Long  ;Should be unsigned long
How to do this?


@duminda The JVM doesn't have unsigned long, only signed long.


(but if you're careful with math you can simulate unsigned long)


is there ever a reason that changing maps to a defrecord would make the program slower? in clojurescript in particular


@awerner32 Hard to say without more information (and I don't know enough about cljs to even hazard a guess -- maybe ask in #clojurescript if no-one comments here). I would say that there's no need to use records unless you want to dispatch on types (via protocols, for example). I hardly ever use records.


(Interestingly, Alex Miller recently commented that although his Clojure Applied book leans heavily on records, he is using them much more sparingly now -- I think he credited clojure.spec for that change but I can't be sure)


interesting. I have pretty tight loops comparing point data in some other data container and I have a branch where I moved that all to records expecting it to help because of smarter field dispatch (?) but I find the record-based version to be almost 50% slower


with :optimizations :advanced


The fastest way to access record field (in Clojure at least, may be the same in cljs) is just to directly use their name -- but that presupposes you're writing functions within the record that implement a protocol...


(defrecord [a b c]
  (some-fn [this x y z] (do-stuff a b x y)))


If you're accessing the record from outside, I guess you're doing (.-a some-record)?


(and hoping that's faster than (:a some-map)?)


When I try to require clj-tagsoup with (require '[pl.danieljanus.tagsoup :as html]) I got error:


Do you guys notice that lein run migrate is very slow?

$ time lein run migrate
real	0m43.549s
user	1m41.920s
sys	0m3.251s
Just a simple create table script. Startup is very slow.


@stardiviner That means the syntax in that file is not valid -- I suspect tagsoup is bringing in an old version...


@seancorfield Am I able to manually fix this locally?


Yup, you can specify a more up-to-date in your project.clj file


What version of tagsoup are you using?


@stardiviner Looks like you should be able to solve that problem by adding [org.clojure/data.xml "0.0.8"] to your :dependencies in project.clj


Unfortunately clj-tagsoup brings in a lot of old dependencies.


@duminda I'm curious, if you run it again, is it faster the second time? (I wonder if part of the time spent was downloading dependencies)


@seancorfield: I’ve ran multiple times now. Both migrate and rollback take 45+secs.


Maybe report it to whichever project those come from?


Ok, will do.


(I've no idea which plugin you're using to get those tasks)


It's worth bearing in mind that Leiningen starts two JVMs so using it for scripting tasks is going to carry quite an overhead.


Still downloading, very slow network. @seancorfield


@seancorfield: Right now I have three lein processes running (Using luminus - lein new luminus myapp +swagger +re-frame +mysql): 1. lein figwheel 2. lein repl then (start) - Running server. Or, lein run 3. lein garden auto And lein run migrate is after all that.


All those JVMs... 🙂


Perhaps a noob mistake, but what I understood was that I have to run lein figwheel, then run server, and perhaps run garden task afterwards. Is there a way to get all these processes into a single JVM?


@duminda Just noticed your timezone. My wife's currently in that timezone 🙂


@duminda I've no idea about Luminus or any of the cljs stuff, sorry.


@seancorfield: No problem. At least now I know I have a problem. 🙂


I use Boot and when developing, I start the Component for each of my apps, all inside a single JVM.


@seancorfield Now it works. Thanks. Is there some new libraries like clj-tagsoup suggested?


No idea. But you can nearly always override old dependencies by specifying more up-to-date versions directly in project.clj. Sometimes you also need to add :exclusions as well.


For clj-tagsoup it's probably a good idea to add :exclusions [org.clojure/clojure] since it otherwise uses a version range [1.2.0,] which can cause problems.


It looks like there's been some recent activity on clj-tagsoup but no new release yet


So I think there will likely be a new release at some point soon maybe...


@stardiviner A lot of the time, Clojure is so stable and backward compatible that old libraries just continue to work for years. Clojure 1.9 tightened up the syntax checking of a number of forms and that highlighted a lot of "bad syntax" in older libraries that just happened to get past the compiler in earlier versions of Clojure. Most library maintainers have been pretty quick to release new versions with fixes.


@duminda So where are you based, if you don't mind me asking? My wife was in Wuhan this weekend and has just taken off from Shanghai, headed back home to San Francisco.


I see. After I mastered Clojure more better, I will try to contribute on things like this. Thanks for your help.


@seancorfield: I’m in Singapore. Not citizen, just working.


@duminda Oh cool. Somewhere I'd love to visit one day.


@stardiviner The whole Maven/Java versions thing with libraries is a giant pain when you're learning Clojure. But you get used to using lein deps :tree to figure out what's going wrong and how to fix stuff.


@seancorfield This is really a great helpful tip.


I find lein deps :tree a whole lot better then any other tool I tried for java to resolve them. Especially the suggestions are nice.


And adding :pedantic? :abort to flush out those nasty version ranges!


(in Boot there's a show task -- boot show -d is the equivalent to lein deps :tree and boot show -p is equivalent to Leiningen's pedantic mode)


Ah, Europe is just coming online I see @gklijs! That's good because it's bedtime here...


@seancorfield yes, the Netherlands, where i live and work, but not to get to far off-topic.


(it just means I can go to sleep and know that there are still folks active here to answer questions! 🙂 )


@seancorfield Have not found :pedantic? :abort in lein deps --help. And execute lein deps :tree :pedantic? :abort report error Unknown deps command :tree.


@stardiviner You put :pedantic? :abort in your project.clj file. See lein sample for all the things you can do in a project.clj file.


Hi, can anybody point me in a direction what this errormessage means or where it comes from?

error in process filter: user-error: Some namespaces are in a bad state: error "class java.lang.String is not a function, but it’s used as such" in inserate.api.mutations 


What is the analogue for React/Redux for cljs?


React wrappers include Om, Reagent and Rum; re-frame is very Redux-like


Thank you


it would be more correct to say that Redux is very re-frame-like, as re-frame predates Redux


Ahh. I think I found it. A String literal in function position. I am used to getting "can not be cast to IFn" with a line number when I do that.


In a project created with luminus template, I have the following code in a file:

(ns ppserver.db.core
    [ :as jdbc]
    [conman.core :as conman]
    [ppserver.config :refer [env]]
    [mount.core :refer [defstate]])
  (:import [java.sql

(defstate ^:dynamic *db*
  :start (conman/connect! {:jdbc-url (env :database-url)})
  :stop (conman/disconnect! *db*))

(conman/bind-connection *db* "sql/queries.sql")
It seems that if the sql/queries.sql file has problems, I can’t even get a repl by doing lein repl:
Exception in thread "main" java.lang.ExceptionInInitializerError
	at clojure.main.<clinit>(
Caused by: clojure.lang.ExceptionInfo: Missing HugSQL Header of :name, :name-, :snip, or :snip-
Is this a problem? I’m unsure because this code is generated by the template. Isn’t having code like (conman/bind-connection *db* "sql/queries.sql") at top level a bad idea?


Hello! Which library should use for "naming routes", like this example: (This looks old and unsupported)


Looks good, but I already use Compojure, bidi - is alternative for it, not addition


@duminda how is your sql/queries.sql file?


There was some problems in it. I fixed them and now it’s fine.


I just want to confirm my understanding of ~/.m2/repository/* (which is where all of the clojure dependencies on our local machines are stored to my knowledge). Whenever we install a CLJ/S dep, in any project we work on our local machines, it is added to this directory, correct? This works because if we were to venture into any of the packages in ~/.m2/repository/*, lets say ~/.m2/repository/cljfmt/cljfmt/* it will have further directories named after the versions you have locally - for example I have 0.5.3 0.5.7 dirs. So in a way, this is like a global node_modules directory. The main difference is that ~/.m2/repository/* is storing everything under directories named after the specific version, so unlike node_modules we do not have to have an .m2 dir inside each of our clojure projects. Would this outline be correct?

Russ Olsen16:03:31

@tkjone I'm certainly no expert on either Maven or Node but what you have outlined is in line with my understanding.


@stardiviner You put :pedantic? :abort in your project.clj file. See lein sample for all the things you can do in a project.clj file.


> Isn’t having code like (conman/bind-connection *db* "sql/queries.sql") at top level a bad idea? @duminda Yes, having side-effecting global state in top-level expressions in a namespace is a very bad idea, in my opinion.


@seancorfield: I get so confused with all these stuff. I gave up trying to figure stuff out and am now just trying to get something working (whatever that works). Fixing the sql/queries.sql solved my problem for the time being. I don’t know what will happen when I do lein uberjar though. That’s a problem for another time I guess :man-shrugging:


hey all, I'm wondering why this code isn't printing "here I am!"


    [cljs.core.async.macros :refer [go]]))

  (println "ok")
  (let [ok (<! (timeout 1000))]
  (println "here i am!")))


    [cljs.core.async :refer [timeout]])
    [cljs.core.async.macros :refer [go]]))


huzzah, thanks!


weird that it didn't give me an error for forgetting it.


in recent versions of cljs you can just refer go directly FYI


wow. opening up the console on that page has a lot of errors


haha yes lots of errors.


I don't think they are all from me though 🙂


thanks @joelsanchez I think I need it in klipse though


but it seems that I don't need to require <!


Been using clojure/clojurescript continuously for close to two weeks now, I find myself wasting more than the usual amount browsing and reading and comparing this and that. Do I use Om/re-frame/reagent/… Which routing library to use? lein or boot? It’s just option paralysis (for me at least). I don’t want so many options - at least not so early. I almost want some authority figure to guarantee: “Here, go use this and this and that to build a web app and you will be fine”. Right now I’m trying to get my head around the language (being a newb) + trying to learn and use some libraries + trying to evaluate all those libraries against each other because there’s so many + trying to grapple with idiosyncrasies of the env + trying to write code that does what I need it to do. Perhaps I’m too dumb for this. Apologies for the rant, don’t mean to diss clojure in any way as I’m just new and perhaps not going at this the correct way. I just wish the learning curve was easier. Any comments are very welcome.

Ryan Radomski17:03:02

Lest conceptual load? I would recommend reagent and lein


re-frame builds on reagent so that list doesn't really make sense, Om Now is dead and Om Next is unstable, so just use re-frame with reagent


you're missing Fulcro 🙂


there, solved 😛

Ryan Radomski17:03:59

you will find superior tooling and some nicer documentation with re-frame


@radomski, @joelsanchez: Actually, I confess I am quite happy with re-frame.

Ryan Radomski17:03:39

If you're already using re-frame it is safe to stick with it.


@duminda you’re not too dumb for this. i was in the same boat not too long ago and had the same reaction. the reality is that cljs tooling is rough in many places and there is no big player like facebook pushing a singular vision forward.


I think it's unfortunate that a lot of Clojure beginners tend to want to learn full-stack so they try to learn cljs + clj at the same time, which means a slew of libraries and tooling and the JVM ecosystem on the back end... and that's a HUGE amount to try to learn at once.


I think it's much better to learn Clojure first, on its own, then pick up ClojureScript once your comfortable since then you'll only need to be learning the tooling, not the syntax/language.


@duminda this is the current state of how Clojure receives newcomers. I'm one myself. I'm a hard learner and even though I've been exposed to Clojure for a really good time now, I still struggle severely with tooling and figuring how things fit together.


The cljs ecosystem is pretty user-hostile, even tho' it has improved dramatically over the last few years.


And that web development book based on Luminus is not a good "first book" for learning the stack (in my opinion). Clojure for the Brave and True, Living Clojure -- those are better ways in, as far as I can tell.


@duminda I have found that authoritative person though, and his stuff helped and are helping me beyond words. Unfortunately he has to make a living of it so it's mostly paid material (although there are many freebies in his website) but he is the sweetest person and extremely engaged in trying to soften the barrier of entry. Check it out if you haven't:


Actually, I was planning to try membership next week!


I can't recommend it enough. Really. Each contact with him is a lesson in humbleness and he really tries to help each step of the way.


Eric is awesome -- love his videos!


the great frustration for me is that the language has not been particularly difficult for me to learn. a few oddities here and there, but mostly pretty straightforward. the frustration for me has been things like: how do i get a repl working and why are there 6 different pieces of software involved to make it work. how do i get an editor working. how do i do normal web dev stuff like install an npm library and get it to work.


Exactly! The language itself is beautiful from the little I have tried so far.

Drew Verlee18:03:33

Are you still having repl issues?


oh yea i gave up on using a repl under my setup. i just rely on print statements and hot reload. if i need to mess with a library i either use planck or i use boot -d. but an actual functional cljs nrepl connection to atom has never worked

Drew Verlee19:03:10

Did you try protorepl?

Drew Verlee19:03:37

I probably won’t be able to help with a more complex project. As i understand, sometimes hot code reloading can get tricky at points with larger codebases


yes that’s what i use. but protorepl does something weird with its nrepl conneciton. thheller tried to explain it to me but it was over my head.

Drew Verlee19:03:56

My guess is ones with lots of stateful components, hense libs like compjure.


i use shadow-cljs because i need something sane for npm modules

Drew Verlee19:03:29

Ah, ok. Then i probably can’t be of any help 🙂


i don’t use a clojure backend. it’s just cljs frontend stuff


but to be fair, protorepl doesn’t work well with figwheel projects either


you can send forms to eval, but none of the other cool stuff like doc strings, autocompletion, etc. works


CIDER was just as clunky and nonfunctional

Drew Verlee19:03:56

Right, I haven’t had much luck with understanding how to utilize figwheel unless it was part of a packaged solution.

Drew Verlee19:03:08

So your not alone in that struggle.

Drew Verlee19:03:40

Luckly, the maintainer of figwheel is getting some funded to work on it.

Drew Verlee19:03:56

So i would expect improvements in the next couple months.


that’s great


That’s pretty cool, though I still find stuff like this insanely complicated I am now recommending that you forgo using lein figwheel and instead run lein repl and then launch figwheel from the Clojure nREPL session. This will allow you to reuse all of your project.clj's nrepl configuration.


@lee.justin.m : I tried atom + proto reply first, had the same sort of trouble you are having, and then switched to cursive. Cursive works better for me so far.


@duminda with clojurescript or with clojure?


I do lein figwheel and then connect to nrepl port with cursive. After that, it’s quite easy to work with.


i actually find it easier to read the source code of big complex libraries and figure out what’s going on, for example, as compared to javascript, where i still can’t follow what people are doing sometimes even though i’m 10 times more experienced in that langauge


Thanks for the comments guys. Appreciate it. I will try guides and perhaps “Clojure for the brave and true” (which seems to be aptly titled)


Since we’re talking about beginner woes, I’ll add my own 🙂 Prefixing symbols with a single quote often confuses me (like with the various forms of require). For example, the main difference between the functions below is one returns a seq of functions in a namespace while the other prints them. I might even expect dir to be implemented using dir-fn. Yet one is prefixed with single quote while the other isn’t. As a beginner this looks like an inconsistency in the API.

(clojure.repl/dir clojure.string)
(clojure.repl/dir-fn 'clojure.string)
I find myself really dependent on clojuredocs as I cannot really determine what a function expects from the docstring alone (e.g. these are both documented as taking a namespace as an argument). I realize it’s likely related to dir being a macro while dir-fn is a function and I need to really go back and re-learn macros 🙂


whose api? the main difference here is macros vs. functions - macros can decide whether to evaluate args, so as a convenience make it so you don't need to quote certain args


what on the surface might look inconsistent is actually the sign of a very consistent underlying structure - instead of a huge number of special case syntaxes, we have forms with arguments, some being functions (all args evaluated before use) and soem macros (processed before usage)


yeah, I'm sure once I have a better mastery of macros it all makes sense


you need not be a master :) the only thing you need to know is that macros receive their arguments unevaluated (as data); functions receive them fully evaluated. quoting is for opting out of evaluation, which naturally isn't needed for macros since their arguments are received unevaluated anyway


also keep in mind that 'a is not the same as a unevaluated. it expands to (quote a), which is what a macro would receive


=> (defmacro foo [x] (prn x))
=> (foo a) 
=> (foo 'a)
(quote a)           


in the specific case of dir / dir-fn, dir-fn exists in order to be an implementation detail for dir


is there a convention for documenting which arguments get evaluated and which do not in macros?


sadly, not that I know of


but the doc string for the macro should make it clear what each argument is for (your milage may vary in practice)


I was thinking instead of writing Prints a sorted directory of public vars in a namespace maybe it could say Prints a sorted directory of public vars in 'nsname but I don’t know if that works generally


To be fair one takes a parameter named nsname while the other is named ns

Russ Olsen19:03:31

@noisesmith So here is a kind of rule of thumb if you are working in a REPL: If you are dealing with an ordinary function, you can always evaluate the function "name". So if you try to evaluate inc you will get something that looks like #object[clojure.core$inc 0x21ab2448 "clojure.core$inc@21ab2448"]. If you are dealing with a macro you or something built in like 'if', then you can't evaluate it: You will get an error message like 'Can't take value of a macro:'. Functions always evaluate their args, macros and those other built-in things like 'if' may or may not. Or you can look at the docstring, but this is way easier to do than it is to talk about.


@russ767: I assume you meant to tag jonathan there

Russ Olsen19:03:47

Sorry @noisesmith. You know me, I just start talking to anyone happens to be standing there.


haha sure thing


In go blocks, if a statement throws an exception, can a statement that is declared further down the go block ever be executed? and if so, is there a way around this?



		(let [_ (/ 1 0)]
		  (println "blah"))
	    (catch whatever, please dont print)
I don’t want blah printed here


between channel input and output, you can expect code inside go to follow relatively normal rules


everything between two channel usages gets put into a function in the go state machine


but a try/catch across multiple channel operations... I wouldn't expect it to work in a sensible way


hmm, yes inside the go block will be takes and puts to different channels


+        (let [{:keys [facts
+                      receipt-handle]} (async/<! chan)
+              information       (core/urpdates facts)]
+          (async/onto-chan chan information)
+          (sqs/delete-message {:receipt-handle receipt-handle :queue-url queue-url}))
+        (catch Exception e "blah"))))


so for exmaple i only want to delete the sqs message when no exception E is thrown


i should be alright then?


interacting with sqs inside a go block is bad - io and such


and in terms of code quality, isolating the api interaction / io from channel ops will lead to better code also


@ben.borders since this is #beginners, in case you are not familiar, core.async go blocks use a small fixed number of threads, and blocking operations like IO inside go blocks can lock up all async operations in the entire app


there's clojure.core.async/thread for launching things that might block, it returns a channel you can read from to get proper async behavior


ahh that makes a lot of sense


regarding the exception handling, I'm not sure how a try/catch surrounding multiple channel ops would even work, maybe someone else can offer advice


simplest usage with deferred values is something like:

    (call-api! {:foo true}))
    (fn [result]
      (prn result)
      (handle result))
    ; do more things when the above function returns...
  (d/catch BadRequestException
    (fn [ex]
      (log/error ex "Bad API call!")))
  ; can chain more things, catch more errors, etc.


there’s an async stream abstraction that works with core-async too


@greg316 that's an excellent point


thanks for the information!


fwiw for other readers: here is a good read on async and blocking io


What resources (besides this Slack, obviously ❤️) are people finding most useful on their journey to using/grokking Clojure, and also what are folks’ current biggest obstacles/difficulties/known unknowns? This can be tools, blogs, videos, books, libraries, people… anything really!


1- books, and the REPL 2- discoverability of tools, and the REPL


Back when I was getting started, I'd say: 1- the REPL (and a pile of books) and 2- translating error messages back to my code, and finding decent documentation, esp. about "the best choice" for various libraries.


(the latter really hasn't improved at all, IMO -- Clojure remains incredibly unopinionated about libraries)


That the official resources are unopinionated is the hardest thing to me. At every corner a new library is indicated or even taken for granted. Newcommers need consistency across learning materials, especially people without a solid programming background or without a background at all. Also, Clojure libraries tend to be robust and opinionated about dependencies and stack, so the lack of a main structure for the beginner to compare the alternatives to can drain ones energy like a succubus.


I think it's fair to say that while Clojure is a perfectly good language for web development, that's definitely not its focus and -- combined with the mindset of preferring composable libraries over frameworks -- that means that for beginners trying to learn Clojure for web development it's an extremely hard path to follow. For all that I'm sure Luminus is a fine "web framework", I think it would be better for a web development book to start with the basic libraries and build up to where a framework might make sense.


Thanks all! FYI I asked a similar question in #clojure on the theory I’d get a complementary perspective, and there’s some great contributions from people over there too:,


I agree with your sentiment about how Web Development should be introduced to newcomers @seancorfield, but the thing is that a lot of us are coming to Clojure/Clojurescript in search of a heaven of elegance and simplicity for Web Development. This is what the language itself gives us, but the ecosystem is really off. Too many people coming to the ecosystem and getting scared not by the language (as one would assume since it is a "lisp") as said earlier, but by the tooling, the libraries and how they connect.


@seancorfield Your comment on clojure not being focused on web development. How do you mean? I understand that the original purpose of clojure would align to this, but given that we have CLJS now and all the efforts being made there, would we not feel that clojure is more and more embracing the wed development narrative?


@U119C0DNY: I was asking a same sort of question yesterday. Add to this rant ides + repl woes which I didn’t include in the original post.


@tkjone ClojureScript is focused on the browser (and the tooling is far from beginner-friendly, even today) and there's still no "official" way to build front ends -- just lots of choices -- and Clojure on the server has no focus on web development.


"a heaven of elegance and simplicity for Web Development" -- there's no such thing (yet).


Folks keep bringing up Rails and praising its opinionated batteries-included but it's still essentially server-side web development -- and that's what I'm comparing Clojure to. If your definition of "Web Development" is full-stack (I hate that phrase) and you're looking for SPA on the front and APIs or web sockets on the back then ClojureScript/Clojure still don't have a solution. Cognitect does a lot of server-side stuff and I haven't seen much focus from them on client-side, and certainly very little on tooling or ecosystem -- that's what I'm saying.


And I don't want to dismiss the huge amount of work they've put in to Clojure (and ClojureScript) and Datomic -- but, so far, it's pretty much been all about what they've needed internally for their projects that has "leaked out" as things like Pedestal etc.


And as y'all are seeing: Clojure/ClojureScript is not easy when it comes to web development -- and the simplicity of the language is swamped by the complexity of modern web development. Hence, my suggestion that trying to learn Clojure(Script) in the context of a full-stack web application is going to be substantially harder than trying to learn Clojure in a purely server-side context.


@seancorfield even setting “full-stack” development aside, I think it is totally possible to go clojurescript first if you have a json endpoint to program your spa against. the real shame is that clojurescript is so very close to being great at web development. it really isn’t far off at all: most of the actual hard stuff already works. that’s what’s super frustrating is that it seems like we’re wiffing the easy stuff


I for one, would not have opportunity to get into any Clojure if it wasn’t through web dev (due to various reasons)


I see. I agree with Sean's assessment if your are trying to approach it from a rails, server-side perspective. But then again, even Rails is having a hard time being Rails. To further this thought, I believe that even the web development world and languages known for web development are all being swamped by complexity. The tooling for everything front end is also insanely complex to the point where people regularly apologize because web development has become so large. Which is one of the reasons I finally came to clojure. But to the original point, and like nakiya said, web development might be, depending on your experience with programming, the most accessible way to get into the language. I have no real thoughts on the best way myself. I read a lot and practiced. All in all, it depends on where you are in your programming journey - early, beginnner, intermediate or advanced - each of these levels is going to change the way the language should be taught. But yes, if I was teaching someone how to clojure from the early learner perspective, I would think of organizing a curriculum like "Learn Python The Hardway"


create-react-app shows that with effort you can kill most of the incidental complexity by using sensible defaults and providing an opinion as to the minimum number of things possible and get people building their project in no time. things that every website must solve have a solution there: installing npm modules, development vs production mode, proxying to an api, minification and bundling, code maps so that the debugger works. that stuff just works if you use CRA. shadow-cljs solves many of these problems, which is why i often steer people towards it, though really i have no business giving advice 🙂


On the flip side, that is the most sensible option for people who have decided to use React. There is still a conversation before the one about create-react-app - which front end framework should I use? Which I think is more paralyzing and where I think most people get lost in the clojure ecosystem. But I am 100% on board with create-react-app and I would likely steer people there if they decided React was what they want to try