34

I am looking at some code in Scheme from Festival and cannot seem to figure out the comments. Currently, I can see ;, ;; and ;;; used to indicate comment lines. Other sources on the web indicate that some of the above maybe ways to indicate multi-line comments. My questions are:

  1. What is the difference between ;, ;; and ;;; for commenting?
  2. When is one to be used over the other?
  3. Is there any other, IMO saner, way to comment code in Scheme?
Sriram
  • 10,298
  • 21
  • 83
  • 136

3 Answers3

52

All three of the forms you mention are single-line comments. The double-semicolon may have originally arisen as a cue in Dorai Sitaram's SLaTeX typesetting package that the comment was to be typeset as ordinary text, rather than as program text.

Scheme also has multi-line comments.

In particular, it appears that R6RS, like Racket, allows the use of #| and |# to begin and end multi-line comments. Also, the utterly magnificent #; combination comments out a full s-expression. So, for instance, if you write

#;(define (terrible-function a)
    (totally-broken-code
     here))

The entire definition is considered commented-out.

Mirzhan Irkegulov
  • 17,660
  • 12
  • 105
  • 166
John Clements
  • 16,895
  • 3
  • 37
  • 52
  • `;#` or just `;` both identical to `#;`, in their effect. –  Dec 04 '17 at 07:29
  • 4
    No, `;#` and `;` are not identical to `#;`... Try running my example code, and then change the `#;` into a `;#` and run again. – John Clements Dec 06 '17 at 21:26
  • 1
    EDIT: perhaps it's not clear that I'm speaking of Racket and R6RS scheme here, and not older or different versions of scheme. Racket and R6RS both support the `#;` form. – John Clements Dec 06 '17 at 21:41
  • 4
    You right, I'm wrong =). `#;`, indeed comments out the whole definition, while `;#` and `;` comment out only single line. P.S.: it was perfectly clear that you were talking about Racket and R6RS scheme, it's just that I have tested it shallowly. –  Dec 07 '17 at 06:54
  • 2
    Well, that's very civil of you. If I upvote your comment, is that appreciative, or just mean? :) – John Clements Dec 09 '17 at 18:36
  • 1
    Very nice to see a reasonably cordial disagreement. I've upvoted all :) – Nathan majicvr.com Jan 01 '20 at 03:39
29

The comment character is ; and anything following that on the line will be ignored. The difference is visual. I have often seen a single ; used if the comment is on a line with code, ;; if the comment is on a line by itself, and ;;; if it's a heading of some sort. The most important thing in commenting is likely to follow whatever conventions you see in the code you're working with.

Gregory Marton
  • 1,429
  • 10
  • 12
3

MIT/GNU Scheme allows the use of ; for single-line comments and #| and |# respectively for opening and closing multiline comments. Just tested on version 10.1.10.