Chapter 14: an enumeration, built
Chapter 14 makes an enumeration: Day, a fixed set of named values that comes with printing, comparing and build-from-text for free - then a kindOf function that switches on it, and a Week program that prints every day. The IDE's own tools make the structure - the enumeration and its seven values in one call, each function's whole signature - so what is left to type is only the logic no tool can write: what kindOf decides, what Week prints. To play it in the IDE: Help > Lessons > Writing code…, or ek9 -ide -lesson book-enumerations.
What you'll build
The lesson builds this program from a file holding only its module line - the finished file, as the book prints it.
#!ek9 defines module book.days defines type Day Monday Tuesday Wednesday Thursday Friday Saturday Sunday defines function kindOf() as pure -> day as Day <- rtn as String: "weekday" switch day case Day.Monday, Day.Tuesday, Day.Wednesday, Day.Thursday, Day.Friday rtn: "weekday" case Day.Saturday, Day.Sunday rtn: "weekend" default rtn: "no such day" defines program Week() stdout <- Stdout() for day in Day stdout.println(`${day} is a ${kindOf(day)}`)
Step 1: An enumeration
Choose Code > New Construct > Type > Enumeration…
Day is the enumeration's name. Add each of the seven days as a value, in order - Monday through Sunday - then choose Preview.
The preview shows Day about to be written, all seven values together; then the IDE formats the file it writes. Choose Apply.
Step 2: kindOf — and its logic
Choose Code > New Construct > Function…
kindOf is the function's name. Add one parameter, day of type Day, set Returns to String, and tick pure. Choose Preview.
The preview shows kindOf about to be written, pure, day in and String out. Choose Apply.
Select the stub, from <- rtn as String? down to its //AI line, and type kindOf's decision: the real return and a switch over every day with a default for the rest. Saves when typed.
Step 3: The program — and its logic
Choose Code > New Construct > Program…
Week is the program's name - no application to bind, no parameters, nothing injected. Type Week and choose Preview.
The preview shows Week about to be written. Choose Apply.
Select the stub, from ready <- true down to its //AI line, and type Week's body: a Stdout, and a line for every day printing what kindOf makes of it. Saves when typed.
Step 4: Run it
Choose Run > Run Program…
The project's only program is already chosen. Choose Run.
Monday is a weekday ... Saturday is a weekend ... Sunday is a weekend - kindOf answers for every day, and the switch never had to guess. Choose Close.
The result
Days.ek9 now reads exactly as chapter 14 of Getting Started with EK9 shows it: an enumeration the tools built in one call, with the function and program that use it, logic you typed. The same three tools - ek9_new_construct (twice: 'type'/'enumeration' and 'function') and ek9_add_program - are what an AI assistant calls to do the same thing.
Where this lesson comes from
- For AI assistants - the MCP tool
ek9_new_construct,ek9_add_program.














