- 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.
推薦閱讀
- Spring 5.0 Microservices(Second Edition)
- 零基礎學C++程序設計
- Java開發入行真功夫
- The Complete Coding Interview Guide in Java
- Android開發:從0到1 (清華開發者書庫)
- Flutter跨平臺開發入門與實戰
- SQL經典實例(第2版)
- C和C++游戲趣味編程
- Learning jQuery(Fourth Edition)
- Statistical Application Development with R and Python(Second Edition)
- .NET Standard 2.0 Cookbook
- Python函數式編程(第2版)
- 從零開始構建深度前饋神經網絡:Python+TensorFlow 2.x
- 美麗洞察力:從化妝品行業看顧客需求洞察
- Java EE互聯網輕量級框架整合開發:SSM+Redis+Spring微服務(上下冊)