Is this Clojure code indented correctly?

http://pastebin.com/d2294a374

I posted the indented code in two different ways. I got confused here because I'm not sure what to do when a function has multiple arguments. Should each argument be on a different line or the same? besides, when we have something like (def xyz (fn abc [a1 a2] ... does (fn abc ... go on another line?

I am reading the following from http://mumble.net/~campbell/scheme/style.txt , but it doesn't seem to make much sense to me.

** Indent and align

An operator of any form, i.e. The first subform following the opening of the parentheses defines the rules for indenting or aligning the remaining shapes. Many names in this alignment or indentation; These are special operators, macros, or procedures that have specific parameter structures.

If the first subform is a non-specific name, however, if the second subform is on the same line, align the start column of all the following subforms with the shape of the second subform. If the second subform includes the next row, align its start column with the first subform and do the same for all other subforms.

In general, Emacs will correctly inject Lisp code. Run `CMq '(indent-sexp) for any code to make sure it is indented correctly and configure Emacs so that any non-standard forms are indented accordingly.

:

(+ (sqrt -1)
  (* x y)
  (+ p q))

(+
   (sqrt -1)
   (* x y)
   (+ p q))

:

(+ (sqrt -1)
   (* x y)
   (+ p q))

(+
 (sqrt -1)
 (* x y)
 (+ p q))

: , , . ; - , .

+3
1

(, ), . , (, 2 ), :

(foo (bar (baz
            arg1
            arg2)))

, , :

(foo (bar (baz arg1
               arg2)))

:

(defn get-neighbors [[x y] v]
  (for [y1 (range (dec y) (+ y 2))
        x1 (range (dec x) (+ x 2))
        :when (and (not (and (= x1 x)
                             (= y1 y)))
                   (in-bounds? x1 y1 v))]
    ((v y1) x1)))
+10

Source: https://habr.com/ru/post/1725681/


All Articles