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

  • Perl 6 Deep Dive
  • Andrew Shitov
  • 165字
  • 2021-07-03 00:05:52

Enumerations

Enumeration is the data type that is used to define, for example, possible values of some concept. For example, traffic light colors take three values:

enum TrafficLight <red yellow green>;

The names of the values become known to Perl 6 and thus you may use them directly in a program, for example:

say red;

This code prints the name of the value:

red

In this example, the actual values of the red, yellow, and green names are not important for us but Perl 6 assigns increasing integer values to them.

say red + yellow + green; # 6

This program is equivalent to say 0 + 1 + 2.

When the values are important, then you can specify them explicitly, as we do in the next example:

enum Floors (
garage => -1, ground-floor => 0,
first => 1, second => 2);

We will see one of the examples of the enumeration in the definition of the Boolean type in Perl 6 in the next section.

主站蜘蛛池模板: 盘锦市| 宁化县| 翁源县| 广西| 修武县| 屏东县| 阳山县| 磴口县| 贵定县| 兰坪| 宁波市| 章丘市| 精河县| 米脂县| 探索| 鸡西市| 调兵山市| 宿迁市| 阳东县| 宁明县| 大理市| 静乐县| 广安市| 汽车| 进贤县| 镇平县| 庆安县| 彰化市| 邵东县| 新乐市| 新丰县| 万盛区| 连州市| 安图县| 临城县| 永春县| 遵义县| 平谷区| 鄂州市| 大兴区| 金山区|