Enumerations: Difference between revisions
Content added Content deleted
(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: | Line 1,772: | ||
<pre> |
<pre> |
||
[1, 2, 3, 4, 5, 6] |
[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> |
</pre> |
||