Why is it customary to put many closing parentheses on one line in Lisp-based languages?

后端 未结 8 1163
野的像风
野的像风 2021-02-05 01:19

Usually code looks like this:

(one-thing
    (another-thing arg1 (f arg5 r))
    (another-thing arg1 (f arg5 r)))

Why doesn\'t it like this?:

8条回答
  •  不知归路
    2021-02-05 01:37

    There are two points to be made here:

    1. Conventions are important in themselves. Sticking to wrapped parens means your code is more readable by other lisp programmers, and if you adopt this style you will also develop practice at reading theirs

    2. The advantages of splitting )s onto their own lines are not actually advantages in the eyes of most lispers. If you are using a half-decent editor it will have commands that understand balanced expressions, for moving across them, cutting, pasting, transposing, etc. So you don't need

      )  ; end of the loop
      

      in lisp any more than you need

      # end of the loop
      

      in some whitespace-sensitive language like Python

    See e.g. http://www.gnu.org/software/emacs/manual/html_node/emacs/Expressions.html

提交回复
热议问题