-
Notifications
You must be signed in to change notification settings - Fork 0
Enums
In Algo, enums are sets of values which correspond to integer values. Here's how you create an enum in Algo:
let myEnum = enum
{
value1,
value2
}
Once you've defined an enum, you can access the values to return and modify by using the usual object access. For this example, it would be myEnum.value1
for the value1
field.
In Algo, enums are simply objects which have variables with the given names (eg. value1 and value2), and a value of integers ascending from zero. So, if you define an enum as above, it's the same as doing:
let myEnum = object {
let value1 = 0;
let value2 = 1;
};
This does also mean that enums are mutable, and can be changed at runtime. This is highly recommended against, as it usually leads to unreliability and lots of spaghetti.
Algo (c) Larry Tang, 2019.
Commercial use of Algo must include the LICENSE
file in the same directory as the executable.
Standard Library Documentation: