mirror of
https://codeberg.org/ziglings/exercises.git
synced 2026-06-08 07:50:00 +00:00
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.
This commit is contained in:
@@ -1,11 +1,35 @@
|
||||
--- exercises/074_comptime9.zig 2023-10-03 22:15:22.125574535 +0200
|
||||
+++ answers/074_comptime9.zig 2023-10-05 20:04:07.176102462 +0200
|
||||
@@ -39,7 +39,7 @@
|
||||
--- 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;
|
||||
|
||||
// And here's the function. Note that the return value type
|
||||
// depends on one of the input arguments!
|
||||
-fn makeLlamas(count: usize) [count]u8 {
|
||||
+fn makeLlamas(comptime count: usize) [count]u8 {
|
||||
var temp: [count]u8 = undefined;
|
||||
var i = 0;
|
||||
// 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'!"),
|
||||
|
||||
Reference in New Issue
Block a user