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

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.

主站蜘蛛池模板: 山阴县| 桃源县| 白朗县| 石楼县| 波密县| 庆元县| 瓮安县| 翁源县| 大埔区| 灵石县| 宜春市| 白玉县| 尚义县| 平阴县| 思南县| 德令哈市| 西林县| 玛纳斯县| 舟山市| 特克斯县| 泽普县| 中西区| 岢岚县| 巴彦淖尔市| 绥江县| 商南县| 蒙自县| 安丘市| 铜陵市| 邯郸市| 西充县| 徐州市| 怀来县| 招远市| 宁蒗| 博白县| 永春县| 三都| 南澳县| 岳普湖县| 凉山|