Enumerations: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Minor tidy)
 
Line 2,179: Line 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.
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="ecmascript">var APPLE = 1
<syntaxhighlight lang="wren">var APPLE = 1
var ORANGE = 2
var ORANGE = 2
var PEAR = 3
var PEAR = 3
Line 2,197: Line 2,197:
<br>
<br>
{{libheader|Wren-dynamic}}
{{libheader|Wren-dynamic}}
<syntaxhighlight lang="ecmascript">import "/dynamic" for Enum
<syntaxhighlight lang="wren">import "./dynamic" for Enum


var Fruit = Enum.create("Fruit", ["apple", "orange", "pear", "cherry", "banana", "grape"], 1)
var Fruit = Enum.create("Fruit", ["apple", "orange", "pear", "cherry", "banana", "grape"], 1)