Fork me on GitHub
#beginners
<
2021-10-16
>
Marc Rios07:10:22

Hi, I'm trying to run a ring server, but every response I get back is an octet/stream object containing zero bytes. I'm pretty sure that I've just copied the examples from "Web Development With Clojure, 3rd edition".. I'm not sure where the problem could be coming from.

Marc Rios07:10:51

Any help or ideas would be appreciated.

Marc Rios07:10:12

Ok, I think the issue was that the reitit routes were missing a pair of brackets.

introom13:10:33

say you have required a namespace x.y.z :as some short name foobar. Now given foobar, how do you get back the qualified name x.y.z ?

alexmiller13:10:35

You can use ns-aliases to look it up

👍 1
introom15:10:06

I noticed two directory layout pattern: 1. - db.clj - db/{x,y,z}.clj 2. - db/{core, x, y, z.}.clj basically in the second one, the previous db.clj is changed to db/core.clj

Ben Sless15:10:40

With the caveat api is nicer than core, I vote 2

thom16:10:56

The second basically guarantees a dozen files called ‘core.clj’ in your project which seems suboptimal to me.

Ben Sless16:10:17

If it's a repository with many types of component.clj and component/{x,y,z}.clj then I agree with thom, 1 is preferable

dorab16:10:28

I don't know that there is an "accepted" layout. Layout 2 (with core.clj) was more common in the past, mainly because that was/is the lein default. Nowadays, the defaults for newer tools (such as deps-new) are Layout 1.

thom17:10:10

I don't mind projects having a single ‘core’ namespace at the project level, although I wouldn't do it if it weren't the convention. But if you use core inside individual components of your app (e.g. what I assume is the database stuff here) I think that's unnecessarily generic.

kennytilton14:10:21

If you have a dozen cores from version 2, @UTF99QP7V, that also means you have a dozen wodges of code that are almost little embedded libraries. So a dozen interfaces (cores) would be appropriate. Me, I find version 1 to be problematic in that it separates the main source from its subordinates, linked only casually by the directory being named the same as the source.clj

introom15:10:12

which one is more accpeted?

Apple15:10:44

i like 2 better

Ed18:10:19

I much prefer 1. Core is just a noise word that doesn't really tell you anything about the namespace and what code it contains. You might as well call it "misc" or "util".

sova-soars-the-sora18:10:20

apples need cores 😄

Ed20:10:36

So do nuclear reactors. Neither of them are for general consumption ;-P

😂 1
GGfpc21:10:18

Hello! I have a question regarding core.async and go blocks. I have an endpoint that makes several asynchronous HTTP calls. To do so I make each call using http-kit and put the result in a channel that is immediately closed. This is so I can merge all the channels together and proceed when all of the requests have finished. Now I used to do blocking waits on the channel, but I'd like to park instead to better use the machine's resources. I thought I would be able to serve the request in a go block and then use >! to park until the results are in, but it says it's not being called inside a go block. From what I understand core.async won't know its not inside a go block if its in an outer function. In that case, how would you suggest I change this code so that I'm not using a thread per request and not blocking until all of the HTTP requests have finished?

(defn call
  [url]
  (let [channel (chan)]
    (http/get url
              (fn [{:keys [_ _ body _]}]     ;; asynchronous response handling
                (async/>!! channel body)
                (async/close! channel)))
    channel))

(defn do-stuff
  [urls]
  (time
    (->> (map call urls)
         (async/merge)
         (async/into '())
         (async/<!))))

(defroutes handler
           (POST "/do-stuff" [] (async/go (do-stuff *urls*))))

Kimo22:10:30

Hey #beginners, Java interop question: If a method is http://caprica.github.io/vlcj/javadoc/4.1.0/uk/co/caprica/vlcj/player/base/MediaApi.html#play-java.lang.String-java.lang.String...-, and reflected at runtime, what does it mean that I still can't call it?

dpsutton22:10:19

check our the requirements to call a varargs method here:

Kimo22:10:52

Beautiful, thank you.