Published
Exhaustive lookup tables in Jik v0.1.0-alpha.22
Jik v0.1.0-alpha.22 is now available. This release adds tables: fixed, module-level lookups that associate every enum member, or every variant tag, with a value of one declared type.
Make complete mappings explicit
A table is checked for completeness at compile time. Each key must appear exactly once, so missing, unknown, and duplicate entries are errors. There is no default entry: when an enum grows, the compiler points to every table that needs updating.
enum Signal:
RED
GREEN
YELLOW
end
table SignalNames[Signal] -> String:
RED: "red"
GREEN: "green"
YELLOW: "yellow"
end
table Durations[Signal] -> int:
RED: 30
GREEN: 25
YELLOW: 5
end
table NextSignal[Signal] -> Signal:
RED: Signal.GREEN
GREEN: Signal.YELLOW
YELLOW: Signal.RED
end
func main():
signal := Signal.RED
for cycle = 0, 6:
println(SignalNames[signal], " for ", Durations[signal], " seconds")
signal = NextSignal[signal]
end
end
Tables are initialized once and their entries cannot be replaced. Use them when you need to associate a value with an enum or variant tag.
Release: Jik v0.1.0-alpha.22 Docs: Tables