What is the recommended method formatting large clauses inside a cond statement in Clojure?
Ex:
(cond
(> (large-function large-arg1
large-arg2
large-arg3)
long-var-name))
(->> (iterate #(* % 6) 1)
(take 10)
(apply +))
(> (large-function large-arg4
large-arg5
large-arg6)
long-var-name))
(->> (iterate #(* % 6) 1)
(take 10)
(apply +))
(> (large-function large-arg7
large-arg8
large-arg9)
long-var-name))
(->> (iterate #(* % 6) 1)
(take 10)
(apply +)))
If the result is on the same line as the condition, the result ends up way too indented, but if the result and the condition are different lines, it becomes too easy to lose track of conditions vs results. This seems like a situation where Common Lisp style cond would be useful, but adding the parentheses (probably brackets in Clojure's case) doesn't seem like the recommended course.
In many cases questions like this default to "format it the way emacs does". Not that I inherently support this philosophy. It is ultimatly up to your sense of aesthetics
in short conds i like:
(cond
(clause1) (action)
(clause2) (action)
for really long ones like yours I like to add some extra newlines as visual delimiters:
(cond
(clause)
(action)
(clause2)
(action2)
so i would format your code:
(cond
(> (large-function large-arg1
large-arg2
large-arg3)
long-var-name)
(->> (iterate #(* % 6) 1)
(take 10)
(apply +))
(> (large-function large-arg4
large-arg5
large-arg6)
long-var-name)
(->> (iterate #(* % 6) 1)
(take 10)
(apply +))
(> (large-function large-arg7
large-arg8
large-arg9)
long-var-name)
(->> (iterate #(* % 6) 1)
(take 10)
(apply +)))
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