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

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.

主站蜘蛛池模板: 巴楚县| 梅河口市| 徐州市| 温泉县| 晋中市| 南涧| 鄯善县| 东乌珠穆沁旗| 宣威市| 田阳县| 新巴尔虎右旗| 密山市| 阿瓦提县| 北碚区| 甘孜| 河池市| 滨海县| 广东省| 松阳县| 垫江县| 东至县| 汉寿县| 平利县| 高邑县| 繁昌县| 墨竹工卡县| 洛浦县| 长宁区| 延津县| 德钦县| 申扎县| 蒙山县| 孟村| 滨海县| 临沂市| 河东区| 涡阳县| 梅州市| 京山县| 金门县| 永宁县|