Enumerations: Difference between revisions

Made the program possible to compile, changed the description of {.pure.} pragma, added vertical presentation, etc.
(Added Wren)
(Made the program possible to compile, changed the description of {.pure.} pragma, added vertical presentation, etc.)
Line 1,079:
 
=={{header|Nim}}==
<lang nim>type# FruitsSimple = enum Apple, Banana, Cherrydeclaration.
type Fruits1 = enum aApple, aBanana, aCherry
 
# Specifying values (accessible using "ord").
type Fruits = enum Apple = 0, Banana = 1, Cherry = 2 # with values
type Fruits2 = enum bApple = 0, bBanana = 2, bCherry = 5
 
# Enumerations with a scope which prevent name conflict.
type FruitsFruits3 {.pure.} = enum Apple, Banana, Cherry # scoped enum
var i: int = Apple # error for scoped enum
type FruitsFruits4 {.pure.} = enum Apple = 03, Banana = 18, Cherry = 2 # with values10
var x = Fruits3.Apple # Need to qualify as there are several possible "Apple".
 
# Using vertical presentation and specifying string representation.
type Fruits = enum Apple = "Apple", Banana = "Banana", Cherry = "Cherry" # with string literals</lang>
type Fruits5 = enum
cApple = "Apple"
cBanana = "Banana"
cCherry = "Cherry"
echo cApple # Will display "Apple".
 
# Specifying values and/or string representation.
type Fruits6 = enum
Apple = (1, "apple")
Banana = 3 # implicit name is "Banana".
Cherry = "cherry" # implicit value is 4.</lang>
 
=={{header|Objeck}}==
Anonymous user