官术网_书友最值得收藏!

  • Perl 6 Deep Dive
  • Andrew Shitov
  • 179字
  • 2021-07-03 00:05:46

Embedded comments

Embedded comments in Perl 6 are comments that use the syntax of multi-line comments, but are placed inside the main code. Unlike the one-line comments, embedded comments are not propagated until the end of the line and may be terminated by the closing character.

Let's demonstrate an example of an embedded comment on the add function, shown as follows:

sub add($x, $y) {
    return $x + #`(this is numeric addition) $y;
}

The #`(this is numeric addition) comment informs the reader that the + operator expects its operands (variables $x and $y in the example) to be numeric values (unlike the concatenation of strings, for example). The whole comment is embedded into the $x + $y expression. After the comment ends, the regular code flow continues. The compiler ignores the comment and, thus, the line remains syntactically correct.

Embedded comments should be as short as possible to make the whole code easier to read. Use it to give small explanations or to temporarily disable a fragment of code during the debugging of the program.

主站蜘蛛池模板: 乐亭县| 宁乡县| 宜丰县| 鹰潭市| 日喀则市| 平乐县| 阳原县| 西充县| 陆河县| 康保县| 长丰县| 五华县| 镇远县| 肃北| 鹤壁市| 房山区| 松滋市| 兴文县| 江安县| 广安市| 凌海市| 满洲里市| 黄龙县| 白银市| 张家川| 万山特区| 海口市| 衡东县| 安徽省| 体育| 吐鲁番市| 连南| 龙里县| 鹿邑县| 长子县| 钟祥市| 山阴县| 买车| 松滋市| 顺平县| 开远市|