I want to indent the following piece of code. How would a lisper indent this? I am especially confused about where to put newlines.
(defn primes [n]
(letfn [(sieve [table removal]
(assoc table removal false))
(primebools [i table]
(cond
(= i n) table
(table i) (recur (inc i)
(reduce sieve
table
(range (* i i) n i)))
:else (recur (inc i)
table)))]
(let [prime? (primebools 2 (apply vector (repeat n true)))]
(filter prime? (range 2 n)))))
(defn primes [n]
(letfn [(sieve [table removal]
(assoc table removal false))
(primebools [i table]
(cond
(= i n) table
(table i) (recur (inc i)
(reduce sieve table
(range (* i i) n i)))
:else (recur (inc i) table)))]
(let [prime? (primebools 2 (apply vector (repeat n true)))]
(filter prime? (range 2 n)))))
Is how I would do it.
In addition to @dnolen's answer, I usually put a new line when there's
cond
block)Then just align and indent lines so that the identations are for the same depth of code.
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