Fork me on GitHub

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 "--------------------------------------")

(command-with-header test5 [] "this command does something" (prn "Command output"))
"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?


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


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


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

šŸ‘ 1

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


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

āœ… 2

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?


explicit version takes precedence over transitive one

Alex Miller (Clojure team)17:03:27

note that this only applies to top level versions


Thanks very much.


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 "", :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[ 0x4a47e29e ""], :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?


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


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


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