- 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.
推薦閱讀
- Learning Scala Programming
- iOS Game Programming Cookbook
- GraphQL學習指南
- LabVIEW入門與實戰開發100例
- Lua程序設計(第4版)
- 大學計算機基礎(第2版)(微課版)
- 微信小程序項目開發實戰
- Scala編程(第5版)
- 3ds Max印象 電視欄目包裝動畫與特效制作
- 奔跑吧 Linux內核
- Ionic3與CodePush初探:支持跨平臺與熱更新的App開發技術
- Cinder:Begin Creative Coding
- 面向對象分析與設計(第3版)
- Learning SaltStack(Second Edition)
- Drools 8規則引擎:核心技術與實踐