Sage
Welcome to Sage
Volume (23%) Hide Volume
Topics
Comments
Sage supports both line comments and block comments. Text inside of comments is completely ignored by Sage.

Line Comments

A line comment starts with a tag named //. This tag is ignored, along with the remainder of the line. For example:

A normal line of Sage. [//] A line comment Another normal line. Normal text [//] line comment

Block Comments

A block comment begins with a tag whose name consists of one or more open curly braces. The comment continues until the matching tag, whose name which consists of the same number of close curly braces. For example:

This is some normal Sage text. This line has [{] a small comment [}] in the middle. Another normal line. [{] These lines are all commented out. They are ignored by Sage [}] More normal text.

Comments do not nest, for example:

A normal line. Normal [{] comment [}] normal. A normal line.

Above, if we added [{] to the start of the second line, and [}] to the end of the same line, we would have invalid code (because the comment ends with the first instance of [}]).

However, because Sage allows any number of curly braces, we can make a block comment that includes other block comments: the outer comment needs to have more curly braces than any of the inner comments. For example:

A normal line. [{{]Normal [{] comment [}] normal[}}]. A normal line.

Above, the outer comment uses two curly braces, and the inner one uses just one. If we wanted to comment out this entire example, we would need at least three curly braces:

[{{{] A normal line. [{{]Normal [{] comment [}] normal[}}]. A normal line. [}}}]

Thus, Sage allows commenting any code out (with block comments), as long as you use a sufficient number of curly braces.

Last Modified: 10/24 9:45:52 am
In this article (top)  View article's Sage markup
10/24 9:45:52 am