Files
ziglings/patches/patches/074_comptime9.patch
T
Tom 2472caa183 Replace exercise 074_comptime9
The exercise no longer needed any modifications to pass due to
advancements in Zig.  This new exercise attempts to teach about
@compileError, @compileLog, and some comptime debugging.  It tries to
help prepare users for the "super bonus challenge" in 075_quiz8.
2026-04-12 07:16:33 -07:00

36 lines
1.4 KiB
Diff

--- exercises/074_comptime9.zig 2026-04-11 21:35:08.132459373 -0700
+++ answers/074_comptime9.zig 2026-04-12 07:13:37.971010827 -0700
@@ -27,12 +27,12 @@
start, // Ready to start a new animal.
l, // This means we've seen an "l", so if we see an "m", we know it's a Llama.
};
- var state = State.start;
+ comptime var state = State.start;
// We return an array of animals representing the creature. (This is why we
// really needed the 'count' parameter. Arrays need a size.)
var animals: [count]Animal = .{undefined} ** count;
- var next_animal: usize = 0;
+ comptime var next_animal: usize = 0;
inline for (fmt) |char| {
@@ -56,7 +56,7 @@
//
// What do you think happens with Gators? Do they join with
// other animals or is this an error?
- 'g' => ???,
+ 'g' => @compileError("Gators refuse to join with other animals."),
else => @compileError("No animal starts with '" ++ char ++ "'!"),
},
@@ -68,7 +68,7 @@
next_animal += 1;
// Something is missing here. After we finish a Llama, we
// need to be ready to _start_ over with a new animal...
- ???
+ state = .start;
},
else => @compileError("Only llamas start with 'l'!"),