Enumerations: Difference between revisions

m
No edit summary
m (→‎{{header|Wren}}: Minor tidy)
 
(One intermediate revision by one other user not shown)
Line 680:
enum
int APPLE, BANANA, CHERRY
fun asText = <|me.name + "(" + me.value + ")"
end
type ExplicitFruits
Line 687 ⟶ 686:
int BANANA = 20
int CHERRY = 1
fun asText = <|me.name + "(" + me.value + ")"
end
type Main
Line 2,181 ⟶ 2,179:
 
The only way to give such a variable a value without setting it explicitly is to add one to the previous such variable which (in effect) is what a C-style enum does. If you declare a variable in Wren without giving it a value, then it is set to the special value ''null'' which is no help here.
<syntaxhighlight lang="ecmascriptwren">var APPLE = 1
var ORANGE = 2
var PEAR = 3
Line 2,199 ⟶ 2,197:
<br>
{{libheader|Wren-dynamic}}
<syntaxhighlight lang="ecmascriptwren">import "./dynamic" for Enum
 
var Fruit = Enum.create("Fruit", ["apple", "orange", "pear", "cherry", "banana", "grape"], 1)
9,477

edits