Fork me on GitHub

Would anyone be willing to help me understand some clojure code in here: - I'm specifically unfamiliar with

(def ^:dynamic *session* nil)
and how it relates to what is going on in
(defn- accept-connection
  "Start accept function, to be invoked on a client thread, given:
    conn - client socket
    name - server name
    client-id - client identifier
    in - in stream
    out - out stream
    err - err stream
    accept - accept fn symbol to invoke
    args - to pass to accept-fn"
  [^Socket conn name client-id in out err accept args]
    (binding [*in* in
              *out* out
              *err* err
              *session* {:server name :client client-id}]
      (with-lock lock
        (alter-var-root #'servers assoc-in [name :sessions client-id] {}))
      (require (symbol (namespace accept)))
      (let [accept-fn (resolve accept)]
        (apply accept-fn args)))
    (catch SocketException _disconnect)
      (with-lock lock
        (alter-var-root #'servers update-in [name :sessions] dissoc client-id))
      (.close conn))))


I'm specifically trying to understand what the dynamic does and how it interacts with (binding


it might help you


Thanks, I'll check it out!


I want to make a small 3D thing with WebGL and ClojureScript. But then I would like to show it on a website using JavaScript (preferably "inside" on one of the existing pages). I don't know many details yet, nor much about web development. But I would like to know, is there a way to achieve this? And what is this way called?

Jacques Desmarais11:11:39

Hi juri, yes it is totally possible. ClojureScript compiles to Javascript, so your code will definitely run in an existing web page.


Ok that's great, thanks!


How do I do it? Do I include the compiled Javascript in my html, and have the code use a div with an id of my chosing? Is it that simple? (I've not yet understood how to even deploy a clojurescript website. Seems I need a server, seems like the resources/public folder isn't enough. Would this server be an obstacle to the above approach?)

Jacques Desmarais12:11:37

Is it that simple? Yes, it can be. Yes you need a server. I would suggest trying shadow-cljs for your tooling.


Ok, thanks again!


I'm trying to remember the order of the arguments in the core functions. As a general rule of thumb, is it correct to expect higher-order functions to have their "most significant" arg in second+ place (for example you would usually use ->> for map and reduce) and functions that operate on data to have their "most significant" arg in first place (-> with assoc, get, etc)


from > By convention, core functions that operate on sequences expect the sequence as their last argument. Accordingly, pipelines containing map, filter, remove, reduce, into, etc usually call for the ->> macro. > > Core functions that operate on data structures, on the other hand, expect the value they work on as their first argument. These include assoc, update, dissoc, get and their -in variants. Pipelines that transform maps using these functions often require the -> macro.

thanks 1

Hello 🤙, I'm trying to use font-awesome from webjars in luminus, and getting a mime-type conflict:

The resource from "" was blocked due to MIME type ("text/html") mismatch (X-Content-Type-Options: nosniff).
When linking the style with {% style "/assets/font-awesome/web-fonts-with-css/css/fontawewsome-all.min.css" %} I think that the crux of it is these two wrappers
        (wrap-webjars (constantly nil))
As suggested by I should be able to use wrap-content-type to wrap to add the right mime type to the style. However trying
        (wrap-webjars (constantly nil))
        {:mime-types {"css" "text/css"}})
(based on the documentation Didn't do anything.. Any idea what can I do?


@ozfraier This is literally a guess, but maybe also try {"min.css" "text/css"} ?


Thank you, I've switched to another way of importing it, but will probably try it later to find out :)

metehan13:11:35 I want to use this chart in my cljs app there is a line ApexCharts(document.querySelector("#chart"), options); is there a way to pass hiccup element to this function instead of using document.querySelector("#chart")


you could use (hash-set \a)


or (conj #{} \a)


but I might actually recommend that you set your defn up to take varargs, which will make a seq regardless, then you can use set


(defn foo [& cs] (set cs))


or my even better advice would be to not take both char and coll of char as valid args and just stick with coll-only. it complicates the logic on both sides of that interface and every time I've done this, I ended up regretting it later.


thanks @alexmiller , your gut sounds right. I’m just playing around in a toy project and I’m overly worried with my own sense of beauty.


How to write a project so that I can run a REPL against a working instance of it and play with data?


this is only needed for deployed apps tho - locally you just lein repl

👍 1

be careful who can access that nrepl

👍 1

here’s a good primer on how to structure your program for live development:

👍 1
Juan Sebastian Pena Rodriguez21:11:49

Hi I don't now if this is the right channel to ask this question 😅 I'm pretty new to clojure and java in general, I'm trying to do lein run in this project ( but I keep getting this error, any help?

java version "12.0.1" 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)


that usually indicates a bad re-packaging of some jars


java has this (seldom used) feature where you can sign jars, and the signature is included as part of the contents of the jar, so if you blindly combine jars to build a new jar, you can end up with a signature from one of the jars and of course doesn't match the combined jar


herm, actually, no, it is a failure of the signature mechanism, but it doesn't look like the kind of failure you get when combining jars


it looks like the project has moved to deps.edn and clj over lein, but has some code to include the deps.edn deps in the project.clj, my guess is that code isn't properly handling some exclusion you need, so you are ending up with two copies of TextDocumentIdentifier


clojure_lsp.handlers$eval10214$loading__6434__auto____10215.invoke(handlers.clj:1) clojure_lsp in that stacktrace seems weird


nah, that is just the code that caused the class that caused the error to load


you get a frame like that in most errors that happen while loading a namespace


oh i missed it was in that repo altogether


i'm used to that being tooling alongside the project you actually care about

Juan Sebastian Pena Rodriguez22:11:28

Thanks a lot for the quick answer, as far I can see the project.clj loads the dependencies from deps.edn like this:

(def +deps+ (-> "deps.edn" slurp edn/read-string))
So the dependencies are only in one place, but maybe deps.edn is loaded implicitly by Clojure :thinking_face: , and that is maybe causing the issue?


deps.edn is not loaded implicitly by Clojure (or explicitly)


clj uses it to compute a classpath in a totally different jvm

👍 1

the maintainer runs its on java 12 and i run it on java 8 without those issues sorry

Juan Sebastian Pena Rodriguez22:11:28

@dpsutton I just tried with Java 8 and It works the problem comes from Java 12 I don't know why. At least it works now, thanks for the tip


he uses java 12. odd that you're hitting that issue

Juan Sebastian Pena Rodriguez22:11:28

And now I tried again with Java 12 and it works 😱, I think it is because everything it is compile now so when I do lein run it only runs the Jar

Juan Sebastian Pena Rodriguez22:11:27

So yeah lein clean it does not work any more, then Java 8 lein run it works then Java 12 lein run it works


so lein clean && lein run on java 12 doesn't work? only if you run on 8 first?

Juan Sebastian Pena Rodriguez22:11:58

yes that is correct, I need to compile it first with Java 8