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

  • 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.

主站蜘蛛池模板: 兖州市| 克什克腾旗| 酒泉市| 米泉市| 建瓯市| 江川县| 张家口市| 瑞安市| 津市市| 科技| 佛教| 石柱| 安新县| 磴口县| 肇州县| 淮滨县| 原阳县| 岳阳市| 怀集县| 红安县| 南雄市| 固始县| 临邑县| 卢湾区| 阜城县| 金坛市| 开原市| 禄丰县| 益阳市| 阿城市| 鄄城县| 平罗县| 福鼎市| 镇巴县| 土默特左旗| 宜昌市| 通化县| 自治县| 墨江| 都江堰市| 渝北区|