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

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.

主站蜘蛛池模板: 石嘴山市| 阿坝县| 鄂托克旗| 萝北县| 三原县| 抚宁县| 祁门县| 梓潼县| 上饶市| 双辽市| 五河县| 新蔡县| 珲春市| 元阳县| 洪泽县| 开原市| 彰化市| 喀喇| 万年县| 深州市| 巴南区| 焦作市| 双流县| 镇江市| 江西省| 张家港市| 德化县| 邯郸县| 琼结县| 海原县| 盐边县| 吉林省| 定边县| 赣榆县| 边坝县| 休宁县| 万山特区| 罗山县| 修武县| 江油市| 六盘水市|