Picky syntax question:

In common lisp cond requires more parenthesization than clojure:

(cond
   ((evenp a) a)        ;if a is even return a
   ((> a 7) (/ a 2))    ;else if a is bigger than 7 return a/2
   ((< a 5) (- a 1))    ;else if a is smaller than 5 return a-1
   (t 17))

vs clojure:

(cond
   (even? a) a  ;if a is even return a
   (> a 7) (/ a 2)      ;else if a is bigger than 7 return a/2
   (< a 5) (- a 1)      ;else if a is smaller than 5 return a-1
   t 17)

Of course, fewer parentheses are usually better, but I'm finding cond
in the second form a little harder to read with more complex clauses:

(defn compare-row [a b]
  ;; compare null rows as > to advance
cursor
  (cond
   (and (nil? a) (nil? b)) [0,0]
   (and (nil? a) (not= b nil)) [1, 0]
   (and (not= a nil) (nil? b)) [-1, 0]
   true (loop [col 0 a a b b]
          (let [cmp (compare-fields (first a) (first b))]
            (if (and (< col (count a)) (= cmp 0))
              (recur (+ 1 col) (rest a) (rest b))
              [cmp,col])))))

In this case it takes some visual parsing to see what the predicates
and results are and if you break them up onto individual lines you
have to count evens to figure out what the results are. The extra
level of indentation in the CL case makes it a lot easier. The only
easy solution I've considered for this is to add an extra blank line
between each clause, but this looks weird.

Any thoughts on this or other approaches?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to