Fork me on GitHub
#beginners
<
2019-11-25
>
ScArcher01:11:07

Would anyone be willing to help me understand some clojure code in here: - https://github.com/clojure/clojure/blob/master/src/clj/clojure/core/server.clj 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]
  (try
    (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)
    (finally
      (with-lock lock
        (alter-var-root #'servers update-in [name :sessions] dissoc client-id))
      (.close conn))))

ScArcher01:11:18

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

Rex01:11:23

it might help you

ScArcher01:11:51

Thanks, I'll check it out!

juri08:11:30

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.

juri12:11:27

Ok that's great, thanks!

juri12:11:19

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.

juri14:11:33

Ok, thanks again!

solf09:11:34

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)

schmee09:11:56

from https://clojure.org/guides/threading_macros#thread-last: > 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 4
Oz09:11:34

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-content-type
        (wrap-webjars (constantly nil))
As suggested by https://github.com/weavejester/ring-webjars/issues/4 I should be able to use wrap-content-type to wrap to add the right mime type to the style. However trying
(wrap-content-type
        (wrap-webjars (constantly nil))
        {:mime-types {"css" "text/css"}})
(based on the documentation https://github.com/ring-clojure/ring/wiki/Content-Types) Didn't do anything.. Any idea what can I do?

acron10:11:29

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

Oz14:11:53

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

metehan13:11:35

https://codepen.io/apexcharts/pen/xYqyYm 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")

tws13:11:57

how do I get a single char into a set? (set \a) fails, as set expects a collection. (into #{} \a) also fails, both are trying to use a char as a sequence. seems ugly to go through (set (str \a)) to get there. (and for my larger problem, can’t just do #{\a}). My real issue is I want a function to accept a collection of chars or a single char, and I dislike switching on type.

alexmiller14:11:56

you could use (hash-set \a)

alexmiller14:11:08

or (conj #{} \a)

alexmiller14:11:46

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

alexmiller14:11:04

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

alexmiller14:11:53

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.

tws14:11:02

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.

evocatus16:11:13

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

joelsanchez16:11:47

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

👍 4
joelsanchez16:11:04

be careful who can access that nrepl

👍 4
schmee16:11:03

here’s a good primer on how to structure your program for live development: http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded

👍 4
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 (https://github.com/snoe/clojure-lsp) 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)

hiredman21:11:45

that usually indicates a bad re-packaging of some jars

hiredman21:11:20

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

hiredman21:11:48

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

hiredman21:11:29

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

dpsutton22:11:06

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

hiredman22:11:49

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

hiredman22:11:06

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

dpsutton22:11:16

oh i missed it was in that repo altogether

dpsutton22:11:31

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?

alexmiller23:11:03

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

alexmiller23:11:24

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

👍 4
dpsutton22:11:07

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

dpsutton22:11:44

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

dpsutton22:11:07

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