Fork me on GitHub
#beginners
<
2022-03-08
>
Gunnar14:03:07

This has me somewhat baffled:

(defmacro command-with-header [fname args description & body]
  `(defn ~fname ~args ~description ~@body  <<<<< FOUND: This ~@body was not supposed to be there.
     (println ~(str fname) ": " ~description)
     (println "--------------------------------------")
     ~@body))

(command-with-header test5 [] "this command does something" (prn "Command output"))
(test5)
Outputs:
"Command output"
test5 :  this command does something
--------------------------------------
"Command output"
The body seems executed twice or something? Why is "Command output" being written once before the first println, and then (as expected) after?

walterl14:03:13

You're seeing "Command output" twice, because ~@body is in there twice.

walterl14:03:26

I'm guessing the first one shouldn't be there.

Gunnar14:03:53

umm, no it definitely should not be in that position. OK thanks.

šŸ‘ 1
Gunnar14:03:05

It seems that clojure does what you tell it to do. šŸ˜¬

walterl14:03:57

> "Do what I mean, not what I say!" šŸ˜

āœ… 2
sheluchin17:03:13

How does dependency resolution work with tool.deps when I explicitly list x as a dep and then a different dep includes a different version of x as a subdep?

delaguardo17:03:23

explicit version takes precedence over transitive one

Alex Miller (Clojure team)17:03:27

note that this only applies to top level versions

sheluchin17:03:47

Thanks very much.

zendevil.eth17:03:08

I have the following handler:

(defn save-student-contact-handler
  [{:keys [path-params current-user params]}]
  (prn params)
  (prn path-params)
  ;; authorize current-user can save contact
  (let [r (db/by-id (read-string (:roleId path-params)))
        res (role/create-contact current-user (:db/id r) params)]
    (prn "r" r)
    (prn "res " res)
    (response res)))
where response is [ring.util.response :refer [response]] and res is printing "res " #:db{:id 17592186045455}. But when Iā€™m sending a response this way with response res , Iā€™m getting status 500 in the client:
{:response {:status 500, :body {:type "exception", :class "java.lang.StackOverflowError"}, :headers {"Content-Type" "application/octet-stream", "X-XSS-Protection" "1; mode=block", "X-Frame-Options" "SAMEORIGIN", "X-Content-Type-Options" "nosniff"}}, :request {:protocol "HTTP/1.1", :remote-addr "127.0.0.1", :headers {"host" "localhost", "cookie" "lms=value=eyJhbGciOiJSUzI1NiJ9.MTc1OTIxODYwNDU0Mzc.C__Y62-bNNfzPabQrOEj-YkxUdLuX51ob8GUEwvDCM3MWkJ4hXltLw4PiaOoTtat2XmtnGLWVNZ6xOKhr-d90o0CrMggfG75MWxnt6VleeODEldHc6M-864oND7fv0sIFJZQLEYzixmF4xWK1myRddK3sonJSidHyDkkOjTh2kEcBpKJwljfnM_4xeHIYxBykKIr3PUj7cXVHlNhXc7H3s7X7UmnKzqjqRnjixBjgyUyInjGsVfcaRQAoGCwkZNK5oYILif4ZHhUKJS7vKRhtqyQt7LchpX4TmBfgBwhg6EZpo3_aBu-628JIXkxq_qQUMLEqHuvVxQhrCCav3pB4g", "content-type" "application/json"}, :server-port 80, :content-type "application/json", :uri "/api/students/17592186045450/contacts", :server-name "localhost", :body #object[java.io.ByteArrayInputStream 0x4a47e29e "java.io.ByteArrayInputStream@4a47e29e"], :scheme :http, :request-method :post}, :headers nil, :app #object[clojure.lang.AFunction$1 0xf264b24 "clojure.lang.AFunction$1@f264b24"], :content-type "application/json", :cookie-jar {"localhost" {"lms" {:value "value=eyJhbGciOiJSUzI1NiJ9.MTc1OTIxODYwNDU0Mzc.C__Y62-bNNfzPabQrOEj-YkxUdLuX51ob8GUEwvDCM3MWkJ4hXltLw4PiaOoTtat2XmtnGLWVNZ6xOKhr-d90o0CrMggfG75MWxnt6VleeODEldHc6M-864oND7fv0sIFJZQLEYzixmF4xWK1myRddK3sonJSidHyDkkOjTh2kEcBpKJwljfnM_4xeHIYxBykKIr3PUj7cXVHlNhXc7H3s7X7UmnKzqjqRnjixBjgyUyInjGsVfcaRQAoGCwkZNK5oYILif4ZHhUKJS7vKRhtqyQt7LchpX4TmBfgBwhg6EZpo3_aBu-628JIXkxq_qQUMLEqHuvVxQhrCCav3pB4g", :path "/api/", :domain "localhost", :raw "lms=value=eyJhbGciOiJSUzI1NiJ9.MTc1OTIxODYwNDU0Mzc.C__Y62-bNNfzPabQrOEj-YkxUdLuX51ob8GUEwvDCM3MWkJ4hXltLw4PiaOoTtat2XmtnGLWVNZ6xOKhr-d90o0CrMggfG75MWxnt6VleeODEldHc6M-864oND7fv0sIFJZQLEYzixmF4xWK1myRddK3sonJSidHyDkkOjTh2kEcBpKJwljfnM_4xeHIYxBykKIr3PUj7cXVHlNhXc7H3s7X7UmnKzqjqRnjixBjgyUyInjGsVfcaRQAoGCwkZNK5oYILif4ZHhUKJS7vKRhtqyQt7LchpX4TmBfgBwhg6EZpo3_aBu-628JIXkxq_qQUMLEqHuvVxQhrCCav3pB4g"}}}}
But I can send the following without problems: (response (:db/id res)) How do I fix this?

hiredman17:03:30

it will depend on what the type of res is (not how it prints) and what response does with that kind of type

hiredman17:03:23

my guess is res is some kind of lazy db reference that presents as a kind of collection and as you walk the collection it pulls in more data from the database, and response sees it as a collection and tries to walk it, which blows the stack

hiredman17:03:46

actually, response does nothing but add whatever you pass it to :body, so some middleware you have (maybe json encoding?) or similar is what is doing it