我是 clojure 的新手,我遇到的主要问题是编写可读代码。我经常以如下所示的函数结束。
(fn rep
([lst n]
(rep (rest lst)
n
(take n
(repeat (first lst)))))
([lst n out]
(if
(empty? lst)
out
(rep
(rest lst) n
(concat out (take n
(repeat
(first lst))))))))
有很多结束括号的组合。减少这种情况或以更容易发现缺失括号的方式对其进行格式化的最佳方法是什么?
最佳答案
使用 Emacs 的 paredit
模式(也在其他一些编辑器中模拟)意味着您通常 - 除非您使用鼠标复制/粘贴/强制非结构化选择 - 处理匹配的括号/大括号/括号和相关缩进,无需计数。
Emacs https://github.com/technomancy/emacs-starter-kit (强烈推荐!)默认情况下为 clojure 启用了 paredit。否则,请参阅 http://emacswiki.org/emacs/ParEdit
关于clojure - 管理 clojure 中的括号数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10095264/