Emacs paren-bouncing makes it easy to syntax check a common
lisp cond but fails badly with clojure cond. Emacs doesn't
even need to know that it is parsing lisp since paren-bouncing
is enabled even in fundamental-mode buffers. However, there
has to be a special parser for clojure.
I guess it just depends on what you are used to but in this
case the syntactic change seems spurious to me.
Tim Daly
Any thoughts on this or other approaches?
> 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?
Try this:
(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])))))
I do this with multi-line lets and hash-map initializations too:
(let [
foo
(calculate-foo arg1)
bar
(calculate-bar arg2)
extra-long-name
(calculate-extra-long-name arg3)]
(do-stuff))
(hash-map
:foo
(calculate-foo arg1)
:bar
(calculate-bar arg2)
:extra-long-name
(calculate-extra-long-name arg3))
> This looks nice but requires more hand-indenting, right? I really like
> being able to select a block in emacs and hit indent-region and get
> predictably tidy code. (The failure of emacs to do this 100% with
> scala code is a pet peeve).
Can't help you there, as I never use auto-indenting (nor emacs).
I tend to write the condition and action on separate lines, and put a
blank comment in between each, like this:
(cond
(even? a) ;if a is even return a
a
;;
(> a 7) ;else if a is bigger than 7 return a/2
(/ a 2)
;;
(< a 5) ;else if a is smaller than 5 return a-1
(- a 1)
;;
:else
17)
just to keep emacs's indentation and cursor movement happy.
--
Dave
emacs bending your mind as nauseum :-)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
Yes, you CAN do that, but SHOULD you? If your code is maintained by
more than one person, and the version of cond used is inconsistent
from namespace to namespace, that's going to cause you a bit of grief
sooner or later!
--
Howard M. Lewis Ship
Creator of Apache Tapestry
The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!