The Language Reference & Guide
- Welcome to Emojicode
- Syntax
- The Basics
- Literals
- Variables and Assignment
- Control Flow
- Classes & Value Types
- Overloading
- Operators
- Optionals
- Errors
- Inheritance and Overriding
- Protocols
- Enumerations
- Types and Namespaces
- Types as Values
- Documentation
- Generics
- Callables
- Packages
- Threads
- Safe and Unsafe Code
- Memory Management
- References
- Appendix: The Emojicode Compiler
Enumerations
Enumerations are a special kind of value type that represent a set of options from which one can be chosen.
Defining an Enumeration
The syntax to define an enumeration is:
enum βΆ π type-identifier type-body
enum-value βΆ πβΆοΈ emoji-id
For example:
π β° π
πβΆοΈπ₯
πβΆοΈπ₯
πβΆοΈπ₯
π
In this example, an enumeration that named β° is defined which offers the values π₯, π₯ and π₯.
Instantiating an Enumeration
Every enumeration automatically provides intializers for all its options, named after the option the instance will represent. Like any value type, enumerations are instantiated with π:
πβ°βΆοΈπ₯β
Enumerations cannot have custom initializers.
Methods
In the manner of any other value types, enumerations can have methods. The following examples shows an enumeration which provides a method that returns a textual description of the chosen value:
π β° π
πβΆοΈπ₯
πβΆοΈπ₯
πβΆοΈπ₯
βοΈ π‘ β‘οΈ π‘π
βͺοΈ π π πβ°βΆοΈπ₯βοΈ π
β©οΈ π€Croissantπ€
π
βͺοΈ π π πβ°βΆοΈπ₯βοΈ π
β©οΈ π€Pancakesπ€
π
βͺοΈ π π πβ°βΆοΈπ₯βοΈ π
β©οΈ π€Baconπ€
π
β©οΈ π€π€
π
π
Comparing Enums
π can be used to compare whether two enum instances are equal:
πβ°βΆοΈπ₯βοΈ β‘οΈ a
πβ°βΆοΈπ₯βοΈ β‘οΈ b
βͺοΈ a π b π
π π€Equalπ€βοΈ
π