Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commenting code in Scheme

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?
like image 332
Sriram Avatar asked Nov 24 '11 10:11

Sriram


People also ask

How do you comment multiple lines on a Scheme?

Multi-line comments have unique start and end tags, and everything between the tags is considered a comment (and ignored) by Scheme. The start tag is #|, the end tag is |#. What a comment should include: Comments are used for adding information to your code.

What is commenting on a code?

In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program. They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters.

How do you comment out code in racket?

Go up to "Racket" in the menu bar and click on "Comment Out with Semicolons." DrRacket will put semicolons in front of each of the highlighted lines. You can block comment using #| and |# . Anything between the two tags will be commented out and Racket will not evaluate it.


3 Answers

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.

like image 56
John Clements Avatar answered Oct 06 '22 09:10

John Clements


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.

like image 27
Gregory Marton Avatar answered Oct 06 '22 10:10

Gregory Marton


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.

like image 2
Matteo Carotta Avatar answered Oct 06 '22 09:10

Matteo Carotta