; 之间有什么区别?和 ;;在 Clojure 代码注释中?

发布于 2024-10-18 20:56:51 字数 463 浏览 3 评论 0原文

在 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)

What is the difference between ; and ;; when starting a comment in Clojure? I see that my text editor colours them differently, so I'm assuming there is notionally some difference.

I also see that Marginalia treats them differently:

; 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

嘿咻 2024-10-25 20:56:51

对于口译员来说,没有什么区别。将 ; ;; ;;;;;;; 视为不同的标题级别。

这是我个人的使用习惯:

;;;; 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

There is no difference as far as the interpreter is concerned. Think of ; ;; ;;; and ;;;; as different heading levels.

Here is my personal use convention:

;;;; 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
浮云落日 2024-10-25 20:56:51

查看 官方说明 的含义;< elisp 中的 /code> 与 ;; :由于 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

Check out the official description of the meaning of ; vs ;; in elisp: since the Clojure indenter is basically the same, it will treat them similarly. Basically, use ; if you are writing a long sentence/description "in the margins" that will span multiple lines but should be considered a single entity. Their example is:

(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

The indenter will make sure those stay lined up next to each other. If, instead, you want to make several unrelated single-line comments next to each other, use ;;.

(let [x 99 ;; as per ticket #425
      y "test"] ;; remember to test this
  (str x y)) ;; TODO actually write this function
烟花易冷人易散 2024-10-25 20:56:51

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

Clojure 并不关心 - ; 中的任何行都会被忽略。至停产。

我相信 CL 有一个传统,即使用越来越多的 ;指示更重要的评论/部分。

Emacs ; to be used for end-of-line comments and will indent in surprising ways if that is not your intent. ;; does not so I usually use ;;.

Clojure doesn't care - any line is ignored from the ; to EOL.

I believe there is a tradition in CL of using increasing numbers of ; to indicate more important comments/sections.

聽兲甴掵 2024-10-25 20:56:51

对于语言来说没有任何意义。 ;comment 的阅读器宏
也许其他工具可以解析它们,但“在 clojure 内”它们是相同的。

no meaning for the language. ; is a reader macro for comment
perhaps other tools parse them but "within clojure" they are the same.

凡尘雨 2024-10-25 20:56:51

从 Clojure 的角度来看没有什么区别。我发现 ;;; 突出一点,但这只是我的意见。

另一方面,边注对它们的处理方式有所不同,因为有时注释应该保留在代码部分(例如许可证),并且这些注释会用 ; 标记。这是一个任意决定,将来可能会改变。

There is no difference from a Clojure-perspective. I find that ;; stands out a little better than ;, but that's only my opinion.

Marginalia on the other hand treats them differently because there are times when a comment should remain in the code section (e.g. license) and those are flagged with ;. This is an arbitrary decision and may change in the future.

烟沫凡尘 2024-10-25 20:56:51

在包括 clojure 模式在内的 emacs lisp 模式中, ;; 的格式遵循位于行开头的约定,并根据上下文与任何其他行一样缩进。 ; 预计在行尾使用,因此,如果您在行首放置单分号注释并希望它跳到行尾,emacs 将不会执行您想要的操作当前上下文的缩进。

例子:

(let [foo 1]
  ;; a comment
  foo) ; a comment

In emacs lisp modes including clojure-mode, ;; is formatted with the convention of being at the beginning of a line, and indented as as any other line, based on the context. ; is expected to be used at the end of a line, so emacs will not do what you want it to if you put a single-semicolon comment at the beginning of a line expecting it to tab to the indentation for the present context.

Example:

(let [foo 1]
  ;; a comment
  foo) ; a comment
始于初秋 2024-10-25 20:56:51

我不确定(没有使用过 Clojure,以前从未听说过),但是

I'm not sure (not used Clojure and never heard of this before), but this thread might help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文