diff options
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | build.zig | 6 | ||||
-rw-r--r-- | exercises/008_quiz.zig | 19 | ||||
-rw-r--r-- | patches/patches/006_strings.patch | 6 | ||||
-rw-r--r-- | patches/patches/008_quiz.patch | 14 | ||||
-rw-r--r-- | patches/patches/036_enums2.patch | 6 | ||||
-rw-r--r-- | patches/patches/051_values.patch | 6 | ||||
-rw-r--r-- | patches/patches/052_slices.patch | 4 | ||||
-rw-r--r-- | patches/patches/054_manypointers.patch | 2 | ||||
-rw-r--r-- | patches/patches/063_labels.patch | 44 | ||||
-rw-r--r-- | patches/patches/076_sentinels.patch | 4 |
11 files changed, 88 insertions, 32 deletions
@@ -41,7 +41,7 @@ Verify the installation and build number of `zig` like so: ```bash $ zig version -0.8.0-dev.1983+xxxxxxxxx +0.9.0-dev.137+xxxxxxxxx ``` Clone this repository with Git: @@ -62,7 +62,7 @@ $ zig build The Zig language is under very active development. In order to be current, Ziglings tracks **development** builds of the Zig compiler rather than versioned **release** builds. The last stable release was `0.7.1`, but Ziglings -needs a dev build with pre-release version "0.8.0" and a build number at least +needs a dev build with pre-release version "0.9.0" and a build number at least as high as that shown in the example version check above. It is likely that you'll download a build which is _greater_ than the minimum. @@ -73,8 +73,9 @@ need to also update the other. ### Version Changes -* 2021-04-21 0.8.0-dev.1983 - std.fmt.format() 'any' format string -* 2021-02-12 0.8.0-dev.1065 - std.fmt.format() 's' (string) format string +* 2021-06-14 0.9.0-dev.137 - std.build.Id `.Custom` is now `.custom` +* 2021-04-21 0.8.0-dev.1983 - std.fmt.format() `any` format string required +* 2021-02-12 0.8.0-dev.1065 - std.fmt.format() `s` (string) format string required ## Advanced Usage @@ -7,7 +7,7 @@ const print = std.debug.print; // When changing this version, be sure to also update README.md in two places: // 1) Getting Started // 2) Version Changes -const needed_version = std.SemanticVersion.parse("0.8.0-dev.1983") catch unreachable; +const needed_version = std.SemanticVersion.parse("0.9.0-dev.137") catch unreachable; const Exercise = struct { /// main_file must have the format key_name.zig. @@ -556,7 +556,7 @@ pub fn build(b: *Builder) void { named_verify.dependOn(&verify_step.step); const chain_verify = b.allocator.create(Step) catch unreachable; - chain_verify.* = Step.initNoOp(.Custom, b.fmt("chain {s}", .{key}), b.allocator); + chain_verify.* = Step.initNoOp(.custom, b.fmt("chain {s}", .{key}), b.allocator); chain_verify.dependOn(&verify_step.step); const named_chain = b.step(b.fmt("{s}_start", .{key}), b.fmt("Check all solutions starting at {s}", .{ex.main_file})); @@ -583,7 +583,7 @@ const ZiglingStep = struct { pub fn create(builder: *Builder, exercise: Exercise, use_healed: bool) *@This() { const self = builder.allocator.create(@This()) catch unreachable; self.* = .{ - .step = Step.init(.Custom, exercise.main_file, builder.allocator, make), + .step = Step.init(.custom, exercise.main_file, builder.allocator, make), .exercise = exercise, .builder = builder, .use_healed = use_healed, diff --git a/exercises/008_quiz.zig b/exercises/008_quiz.zig index eda66b8..5a81fb2 100644 --- a/exercises/008_quiz.zig +++ b/exercises/008_quiz.zig @@ -1,7 +1,7 @@ // // Quiz time! Let's see if you can fix this whole program. // -// This is meant to be challenging. +// You'll have to think about this one a bit. // // Let the compiler tell you what's wrong. // @@ -13,14 +13,23 @@ pub fn main() void { // What is this nonsense? :-) const letters = "YZhifg"; - const x: u8 = 1; + // Note: usize is an unsigned integer type used for...sizes. + // The exact size of usize depends on the target CPU + // architecture. We could have used a u8 here, but usize is + // the idiomatic type to use for array indexing. + // + // There IS a problem on this line, but 'usize' isn't it. + const x: usize = 1; - // This is something you haven't seen before: declaring an array - // without putting anything in it. There is no error here: + // Note: When you want to declare memory (an array in this + // case) without putting anything in it, you can set it to + // 'undefined'. There is no problem on this line. var lang: [3]u8 = undefined; // The following lines attempt to put 'Z', 'i', and 'g' into the - // 'lang' array we just created. + // 'lang' array we just created by indexing the array + // 'letters' with the variable 'x'. As you can see above, x=1 + // to begin with. lang[0] = letters[x]; x = 3; diff --git a/patches/patches/006_strings.patch b/patches/patches/006_strings.patch index 040a73c..7e7465c 100644 --- a/patches/patches/006_strings.patch +++ b/patches/patches/006_strings.patch @@ -1,12 +1,12 @@ -22c22 +25c25 < const d: u8 = ziggy[???]; --- > const d: u8 = ziggy[4]; -26c26 +29c29 < const laugh = "ha " ???; --- > const laugh = "ha " ** 3; -33c33 +36c36 < const major_tom = major ??? tom; --- > const major_tom = major ++ " " ++ tom; diff --git a/patches/patches/008_quiz.patch b/patches/patches/008_quiz.patch index 3d35a5a..a62be07 100644 --- a/patches/patches/008_quiz.patch +++ b/patches/patches/008_quiz.patch @@ -1,12 +1,16 @@ -16c16 -< const x: u8 = 1; +22c22 +< const x: usize = 1; --- -> var x: u8 = 1; -27c27 +> var x: usize = 1; +26c26 +< // 'undefined'. There is no problem on this line. +--- +> // 'undefined'. There is no error here. +36c36 < lang[???] = letters[x]; --- > lang[1] = letters[x]; -29,30c29,30 +38,39c38,39 < x = ???; < lang[2] = letters[???]; --- diff --git a/patches/patches/036_enums2.patch b/patches/patches/036_enums2.patch index 54a7094..c20905a 100644 --- a/patches/patches/036_enums2.patch +++ b/patches/patches/036_enums2.patch @@ -1,12 +1,12 @@ -32c32 +34c34 < blue = ???, --- > blue = 0x0000ff, -54c54 +56c56 < \\ <span style="color: #{}">Blue</span> --- > \\ <span style="color: #{x:0>6}">Blue</span> -59c59 +62c62 < @enumToInt(???), // Oops! We're missing something! --- > @enumToInt(Color.blue), // Oops! We're missing something! diff --git a/patches/patches/051_values.patch b/patches/patches/051_values.patch index 43d1f65..6d3c53b 100644 --- a/patches/patches/051_values.patch +++ b/patches/patches/051_values.patch @@ -1,12 +1,12 @@ -96c96 +95c95 < const print = ???; --- > const print = std.debug.print; -152c152 +160c160 < levelUp(glorp, reward_xp); --- > levelUp(&glorp, reward_xp); -157c157 +166c166 < fn levelUp(character_access: Character, xp: u32) void { --- > fn levelUp(character_access: *Character, xp: u32) void { diff --git a/patches/patches/052_slices.patch b/patches/patches/052_slices.patch index 80f8d72..24803d7 100644 --- a/patches/patches/052_slices.patch +++ b/patches/patches/052_slices.patch @@ -1,10 +1,10 @@ -34,35c34,35 +35,36c35,36 < const hand1: []u8 = cards[???]; < const hand2: []u8 = cards[???]; --- > const hand1: []u8 = cards[0..4]; > const hand2: []u8 = cards[4..]; -45c45 +46c46 < fn printHand(hand: ???) void { --- > fn printHand(hand: []u8) void { diff --git a/patches/patches/054_manypointers.patch b/patches/patches/054_manypointers.patch index 82824e8..d8d2e6c 100644 --- a/patches/patches/054_manypointers.patch +++ b/patches/patches/054_manypointers.patch @@ -1,4 +1,4 @@ -33c33 +35c35 < const zen12_string: []const u8 = zen_manyptr; --- > const zen12_string: []const u8 = zen_manyptr[0..21]; diff --git a/patches/patches/063_labels.patch b/patches/patches/063_labels.patch index 2f54a43..aba02a4 100644 --- a/patches/patches/063_labels.patch +++ b/patches/patches/063_labels.patch @@ -1,4 +1,46 @@ -132,133c131,132 +20c20 +< // statement. Does that mean you can return a value from any +--- +> // statement. Does that mean you can return a value from any +28,30c28,30 +< // Labels can also be used with loops. Being able to break out of +< // nested loops at a specific level is one of those things that +< // you won't use every day, but when the time comes, it's +--- +> // And all of that also applies to loops. Being able to break out +> // of nested loops at a specific level is one of those things +> // that you won't use every day, but when the time comes, it's +32,33c32 +< // inner loop is sometimes so handy, it almost feels like cheating +< // (and can help you avoid creating a lot of temporary variables). +--- +> // inner loop is is almost too beautiful to look at directly: +41,44c40,44 +< // In the above example, the break exits from the outer loop +< // labeled "two_loop" and returns the value 2. The else clause is +< // attached to the outer two_loop and would be evaluated if the +< // loop somehow ended without the break having been called. +--- +> // The break exits from the outer loop labeled "two_loop" and +> // returns the value 2. The else clause is attached to the outer +> // two_loop and would be evaluated if the loop somehow ended +> // without the break having been called. (Impossible in this +> // case.) +55,56c55,56 +< // As mentioned before, we'll soon understand why these two +< // numbers don't need explicit types. Hang in there! +--- +> // As mentioned before, we'll soon understand why these numbers +> // don't need explicit types. Hang in there! +100c100 +< // numbers (based on array position) will be fine for our +--- +> // numbers (based on array position!) will be fine for our +108c108 +< // Now look at each required ingredient for the Food... +--- +> // Now look at each required ingredient for the food... +131,132c131,132 < break; < }; --- diff --git a/patches/patches/076_sentinels.patch b/patches/patches/076_sentinels.patch index 33e4483..5c757aa 100644 --- a/patches/patches/076_sentinels.patch +++ b/patches/patches/076_sentinels.patch @@ -1,8 +1,8 @@ -83c83 +86c86 < for (???) |s| { --- > for (my_seq) |s| { -95c95 +98c98 < while (??? != my_sentinel) { --- > while (my_seq[i] != my_sentinel) { |