Skip to content
C272 edited this page Jun 30, 2019 · 4 revisions

Creating 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.

Enums as Objects

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.