Enumerations: Difference between revisions

→‎[[Toka]]: Updated to reflect the addition of enum| function in Toka 1.1
No edit summary
(→‎[[Toka]]: Updated to reflect the addition of enum| function in Toka 1.1)
Line 225:
[[Category:Toka]]
 
Toka has no data types, and therefore no actual enumeration type. TheThere forthis approachan
optional library function which does provide a way to create enumerated
of creating a defining word such as the following will work:
values easily though.
 
This library function takes a starting value and a list of names as shown in the
[ ( n "name" -- n+1 )
example below.
dup is-data 1+ ] is enum
 
] isneeds enum|
This word defines a new constant of the value specified and returns the next
0 enum| apple banana cherrycarrot |
value in sequence. It would be used like this:
10 enum| foo bar baz |
 
0 enum apple enum banana enum cherry drop
 
In addition, a more complex creation function allows cleaner creation of enumerations:
 
[ parser off
[ dup 1 + swap
wsparse dup c@ char: | <>
[ is-data TRUE ] [ 2drop FALSE ] ifTrueFalse
] whileTrue
parser on
drop
] is enum|
0 enum| apple banana cherry |
 
==[[Visual Basic .NET]]==
Anonymous user