|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
enumsIn Nim, enums are ordinal types. They have an order, they can be used in Normal enumsUnder normal I mean non-pure enums. type Color = enum colRed, colGreen, colBlue let color1: Color = colRed color2 = colGreen # can be used alone color3 = Color.colBlue # can be prefixed with the name of the enum echo color1 # colRed echo color2 # colGreen echo color3 # colBlue Since these enum values are usually used alone, it's a good idea to give a prefix to these values. Thus, for instance, instead of " Pure enumstype Color {.pure.} = enum # !!! {.pure.} pragma is used !!! red, green, blue let color1: Color = Color.red #color2 = green # error: cannot be used alone color3 = Color.blue # MUST be prefixed with the name of the enum echo color1 # red echo color3 # blue Notice the usage of the From the manual: "An enum type can be marked as pure. Then access of its fields always requires full qualification." |
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |