Enums and flags
Enums
An enum value has a fixed set of possibilities.
Short enums can be squeezed onto a single line.
Enums support all the same auto functions as records, plus functions for converting to/from numbers and symbols.
"match" on enums
A more convenient way to use an enum is with a match expression.
Enum numbers
Flags
A flags value can contain any combination of the declared flags.
Declaring a flags type implicitly defines several additional functions.
The above example defines:
| Function | Use |
|---|---|
new actions() | Value with no flags set. |
carry actions() | Value with just the carry flag set. |
eat actions() | Value with just the eat flag set. |
toss actions() | Value with just the toss flag set. |
~ actions(a actions) | Value with the opposite flags set. |
| actions(a actions, b actions) | Union; contains any flags that appear in either argument. |
& actions(a actions, b actions) | Intersection; contains only the flags that both arguments agree on. |
subscript bool(a actions, b actions) | True if a contains every flag in b.
Written as a[b]. |
flags types also support all the usual auto functions.