Enumerations: Difference between revisions

→‎{{header|Wren}}: Added a library based version.
(Made the program possible to compile, changed the description of {.pure.} pragma, added vertical presentation, etc.)
(→‎{{header|Wren}}: Added a library based version.)
Line 1,772:
<pre>
[1, 2, 3, 4, 5, 6]
</pre>
<br>
It is also possible to create an enum-like class using read-only static properties to get the values. The following code creates such a class dynamically at runtime. Note that the convention in Wren is for properties to begin with a lower-case letter.
<br>
{{libheader|Wren-dynamic}}
<lang ecmascript>import "/dynamic" for Enum
 
var Fruit = Enum.create("Fruit", ["apple", "orange", "pear", "cherry", "banana", "grape"], 1)
System.print(Fruit.orange)
System.print(Fruit.members[Fruit.cherry - 1])</lang>
 
{{out}}
<pre>
2
cherry
</pre>
 
9,476

edits