by tmtvl · 2y ago · 0 comments
(let ((a 1)
((b c) (list 2 3))
(d e (values 4 5)))
`#(,a ,b ,c ,d ,e))
;; => #(1 2 3 4 5) (let [a 1
[b c] (list 2 3)
[d e] [4 5]]
`(~a ~b ~c ~d ~e))
;; => (1 2 3 4 5) (let ((quotient remainder (floor x y)))
(+ (* quotient z)
(* remainder (floor z y))))
Where floor is a function which returns multiple values rather than a list or vector of results?Also, but this is entirely on me being an absolute dullard, I like having the brackets around each binding as a kind of guardrails for my mind to not lose track of where I am and what belongs where.
(let [[quotient remainder] (floor x y)]
(+ (* quotient z)
(* remainder (first (floor z y)))))
Because in Clojure there's no multiple value bind, when you want to return many results from a function, you wrap it in a vector, and that means you than just destructure that vector. That also means, it's not smart enough to know if it's used in a single value context or multi value context, so you need to always get the value out of the vector, which is why I call first in that second call to floor.