76

在 Clojure 中开始评论;和开始评论有什么区别?;;我看到我的文本编辑器为它们着色不同,所以我假设在理论上存在一些差异。

我还看到Marginalia以不同的方式对待它们:

; Stripped entirely
;; Appears in text section of marginalia
(defn foobar []
   ; Appears in code section of marginalia output
   ;; Again, appears in code section of marginalia output
   6)
4

7 回答 7

86

就口译员而言,没有区别。将; ;; ;;;;;;;视为不同的标题级别。

这是我的个人使用约定:

;;;; Top-of-file level comments, such as a description of the whole file/module/namespace

;;; Documentation for major code sections (i.e. groups of functions) within the file.

;; Documentation for single functions that extends beyond the doc string (e.g. an explanation of the algorithm within the function)

; In-line comments possibly on a single line, and possibly tailing a line of code
于 2011-02-22T22:50:19.350 回答
33

查看elisp中vs含义的官方说明:由于Clojure压头基本相同,所以会一视同仁。基本上,如果您正在“在空白处”写一个长句子/描述,它将跨越多行但应该被视为一个实体,请使用。他们的例子是:;;;;

(setq base-version-list                 ; there was a base
      (assoc (substring fn 0 start-vn)  ; version to which
             file-version-assoc-list))  ; this looks like
                                        ; a subversion

压头将确保它们彼此相邻排列。相反,如果您想将多个不相关的单行注释放在一起,请使用;;.

(let [x 99 ;; as per ticket #425
      y "test"] ;; remember to test this
  (str x y)) ;; TODO actually write this function
于 2012-01-11T19:01:48.763 回答
15

埃马克斯;用于行尾注释,如果这不是您的意图,则会以令人惊讶的方式缩进。;; 不,所以我通常使用;;。

Clojure 不在乎 - 从 ; 中忽略任何行 到停产。

我相信 CL 有使用越来越多的 ; 表示更重要的评论/部分。

于 2011-02-22T22:44:39.143 回答
7

对语言没有意义。;可能是其他工具解析它们的阅读器宏,comment 但“在 clojure 内”它们是相同的。

于 2011-02-22T22:05:20.350 回答
6

与 Clojure 视角没有区别。我发现这;;比 好一点;,但这只是我的意见。

另一方面,Marginalia 以不同的方式对待它们,因为有时注释应该保留在代码部分(例如许可证)中,而那些被标记为;. 这是一个武断的决定,将来可能会改变。

于 2011-02-23T01:11:37.403 回答
6

在包括 clojure-mode 在内的 emacs lisp 模式;;中,根据上下文,按照位于行首的约定进行格式化,并像任何其他行一样缩进。;预计将在行尾使用,因此如果您在行首放置一个单分号注释并期望它在当前上下文的缩进处制表符,那么 emacs 将不会执行您想要的操作。

例子:

(let [foo 1]
  ;; a comment
  foo) ; a comment
于 2011-02-28T05:45:25.700 回答
1

我不确定(没有使用过 Clojure 并且以前从未听说过),但这个线程 可能会有所帮助。

于 2011-02-22T21:50:48.997 回答