Nim Tutorial (Part I) 0.17.1
e x am p l e : type Direction = enum north, east, south, west var x = south # ‘x‘ is of type ‘Direction‘; its value is ‘south‘ echo x # writes "south" to ‘stdout‘ Al l t h e c om p ar i s on op e r at m e r at i on ’ s s y m b ol c an b e q u al i fi e d t o av oi d am b i gu i t i e s : Direction.south. T h e $ op e r at or c an c on v e r t an y e n u m e r at i on v al u e t o i t s n am e , an d north, east, south, west BlinkLights = enum off, on, slowBlink, mediumBlink, fastBlink LevelSetting = array[north..west, BlinkLights] var level: LevelSetting level[north] = on level[south] = slowBlink0 码力 | 24 页 | 271.23 KB | 1 年前3Nim 2.0.8 Manual
evaluated if p == nil p = p.next type Direction = enum north, east, south, west The implied order is: north < east < south < west. The comparison operators can be used with enumeration types. Instead type of foo is ambiguous, a static error will be produced. ord(north) == 0 ord(east) == 1 ord(south) == 2 ord(west) == 3 # Also allowed: ord(Direction.west) == 3 type TokenType = enum a = 2, b0 码力 | 132 页 | 5.73 MB | 1 年前3Nim 2.0.2 中文手册
html)中,可以表示任意 Unicode 字符。 枚举类型 枚举类型定义了⼀个其值由指定的值组成的新类型,这些值是有序的。例如: 以下情况成⽴: 由此可知,north < east < south < west。⽐较运算符可以与枚举类型⼀起使⽤。枚举值也可以使⽤它所在的枚举类型来限定,如 north 可以⽤ Direction.nort 来限定。 为了更好地与其他编程语⾔连接,可以 p == nil, p.name 不被求值 p = p.next type Direction = enum north, east, south, west ord(north) == 0 ord(east) == 1 ord(south) == 2 ord(west) == 3 # 也允许: ord(Direction.west) == 3 但是,它不再是序数,因此不可能将这些枚举⽤作数组类型的索引。0 码力 | 127 页 | 7.05 MB | 1 年前3Computer Programming with the Nim Programming Language
needed, such as the colors red, yellow, and green for a traffic light, or the directions north, south, east, and west for a map or a game. Most of the time, we declare an enum type and the corresponding0 码力 | 865 页 | 7.45 MB | 1 年前3Computer Programming with the Nim Programming Language
needed, such as the colors red, yellow, and green for a traffic light, or the directions north, south, east, and west for a map or a game. Most of the time, we declare an enum type and the corresponding0 码力 | 784 页 | 2.13 MB | 1 年前3Computer Programming with the Nim Programming Language
needed, such as the colors red, yel low, and green for a traffic light, or the directions north, south, east, and west for a map or a game. Most of the time, we declare an enum type and the corresponding0 码力 | 512 页 | 3.54 MB | 1 年前3Computer Programming with the Nim Programming Language
needed, such as the colors red, yel low, and green for a traffic light, or the directions north, south, east, and west for a map or a game. Most of the time, we declare an enum type and the corresponding0 码力 | 508 页 | 3.50 MB | 1 年前3Computer Programming with the Nim Programming Language
needed, such as the colors red, yel low, and green for a traffic light, or the directions north, south, east, and west for a map or a game. Most of the time, we declare an enum type and the corresponding0 码力 | 512 页 | 3.53 MB | 1 年前3Computer Programming with the Nim Programming Language
needed, such as the colors red, yel low, and green for a traffic light, or the directions north, south, east, and west for a map or a game. Most of the time, we declare an enum type and the corresponding0 码力 | 508 页 | 3.54 MB | 1 年前3Computer Programming with the Nim Programming Language
needed, such as the colors red, yel low, and green for a traffic light, or the directions north, south, east, and west for a map or a game. Most of the time, we declare an enum type and the corresponding0 码力 | 508 页 | 3.50 MB | 1 年前3
共 31 条
- 1
- 2
- 3
- 4