How to backtrack clojure / lisp?

I want to delay the next piece of code. How to do it? I am particularly confused by the question of where to put new lines.

(defn primes [n] (letfn [(sieve [table removal] (assoc table removal false)) (primebools [i table] (cond (= in) table (table i) (recur (inc i) (reduce sieve table (range (* ii) ni))) :else (recur (inc i) table)))] (let [prime? (primebools 2 (apply vector (repeat n true)))] (filter prime? (range 2 n))))) 
+7
source share
2 answers
 (defn primes [n] (letfn [(sieve [table removal] (assoc table removal false)) (primebools [i table] (cond (= in) table (table i) (recur (inc i) (reduce sieve table (range (* ii) ni))) :else (recur (inc i) table)))] (let [prime? (primebools 2 (apply vector (repeat n true)))] (filter prime? (range 2 n))))) 

I would do that.

+5
source

In addition to @dnolen's answer, I usually add a new line when there is

  • new function (e.g. your first two lines)
  • to defer a long or important function argument (e.g. cond block)
  • logically save each line to less than 80 characters and split long ideas into smaller pieces.
  • The most important thing is to be consistent!

Then just align and indent so that the identifiers are the same code depth.

+1
source

All Articles