I came across this elegant implementation of Pascal's triangle that uses a lazy sequence.
(def pascal
(iterate
(fn [prev-row]
(->>
(concat [[(first prev-row)]] (partition 2 1 prev-row) [[(last prev-row)]])
(map (partial apply +) ,,,)))
[1M]))
Could anyone help me understanding the ,,,
in this context? I tried using macroexpand
but that didn't get me far. I also know it's use is not required, but I want to know that ,,,
means.
Commas are treated as white space in Clojure so Reader will ignore ,,,
completely. The reason it is there is to make the code more readable for humans.
In this context, the ->>
macro will insert the (concat ...)
in the last position of the call to (map ...)
, i.e. in the position of ,,,
.
The ,,,
commonly used with ->
and ->>
macros to make the code more readable, but does not actually do anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With