diff options
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | build.zig | 6 | ||||
-rw-r--r-- | exercises/003_assignment.zig | 4 | ||||
-rw-r--r-- | exercises/026_hello2.zig | 1 | ||||
-rw-r--r-- | exercises/043_pointers5.zig | 1 | ||||
-rw-r--r-- | exercises/050_no_value.zig | 3 | ||||
-rw-r--r-- | exercises/064_builtins.zig | 40 | ||||
-rw-r--r-- | exercises/065_builtins2.zig | 2 | ||||
-rw-r--r-- | exercises/079_quoted_identifiers.zig | 2 | ||||
-rw-r--r-- | exercises/082_anonymous_structs3.zig | 2 | ||||
-rw-r--r-- | patches/patches/064_builtins.patch | 4 |
11 files changed, 44 insertions, 24 deletions
@@ -41,7 +41,7 @@ Verify the installation and build number of `zig` like so: ```bash $ zig version -0.10.0-dev.1427+xxxxxxxxx +0.10.0-dev.3385+xxxxxxxxx ``` Clone this repository with Git: @@ -81,6 +81,7 @@ about input: ### Version Changes +* *2022-07-31* zig 0.10.0-dev.3385 - std lib string fmt() option changes * *2022-03-19* zig 0.10.0-dev.1427 - method for getting sentinel of type changed * *2021-12-20* zig 0.9.0-dev.2025 - `c_void` is now `anyopaque` * *2021-06-14* zig 0.9.0-dev.137 - std.build.Id `.Custom` is now `.custom` @@ -8,7 +8,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.10.0-dev.1427") catch unreachable; +const needed_version = std.SemanticVersion.parse("0.10.0-dev.3385") catch unreachable; const Exercise = struct { /// main_file must have the format key_name.zig. @@ -64,7 +64,7 @@ const exercises = [_]Exercise{ }, .{ .main_file = "004_arrays.zig", - .output = "Fourth: 7, Length: 8", + .output = "First: 2, Fourth: 7, Length: 8", .hint = "There are two things to complete here.", }, .{ @@ -331,7 +331,7 @@ const exercises = [_]Exercise{ }, .{ .main_file = "064_builtins.zig", - .output = "1101 + 0101 = 0010 (true). Furthermore, 11110000 backwards is 00001111.", + .output = "1101 + 0101 = 0010 (true). Without overflow: 00010010. Furthermore, 11110000 backwards is 00001111.", }, .{ .main_file = "065_builtins2.zig", diff --git a/exercises/003_assignment.zig b/exercises/003_assignment.zig index 6a4364b..10ba8cb 100644 --- a/exercises/003_assignment.zig +++ b/exercises/003_assignment.zig @@ -12,7 +12,7 @@ // var bar: u8 = 20; // // Example: foo cannot be negative and can hold 0 to 255 -// bar CAN be negative and can hold −128 to 127 +// bar CAN be negative and can hold -128 to 127 // // const foo: u8 = 20; // const bar: i8 = -20; @@ -26,7 +26,7 @@ // You can do just about any combination of these that you can think of: // // u32 can hold 0 to 4,294,967,295 -// i64 can hold −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 +// i64 can hold -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 // // Please fix this program so that the types can hold the desired values // and the errors go away! diff --git a/exercises/026_hello2.zig b/exercises/026_hello2.zig index 237d27c..cb29193 100644 --- a/exercises/026_hello2.zig +++ b/exercises/026_hello2.zig @@ -10,7 +10,6 @@ const std = @import("std"); // that Zig will infer the error type. This is appropriate in the case // of main(), but can have consequences elsewhere. pub fn main() !void { - // We get a Writer for Standard Out so we can print() to it. const stdout = std.io.getStdOut().writer(); diff --git a/exercises/043_pointers5.zig b/exercises/043_pointers5.zig index ae80ecc..f3a9ca0 100644 --- a/exercises/043_pointers5.zig +++ b/exercises/043_pointers5.zig @@ -62,7 +62,6 @@ pub fn main() void { // Note how this function's "c" parameter is a pointer to a Character struct. fn printCharacter(c: *Character) void { - // Here's something you haven't seen before: when switching an enum, you // don't have to write the full enum name. Zig understands that ".wizard" // means "Class.wizard" when we switch on a Class enum value: diff --git a/exercises/050_no_value.zig b/exercises/050_no_value.zig index 8708d2d..8c73ed3 100644 --- a/exercises/050_no_value.zig +++ b/exercises/050_no_value.zig @@ -71,7 +71,8 @@ pub fn main() void { var first_line2: Err!*const [21]u8 = ???; first_line2 = "which can eternal lie"; - std.debug.print("{s} {s} / ", .{ first_line1, first_line2 }); + // Note we need the "{!s}" format for the error union string. + std.debug.print("{s} {!s} / ", .{ first_line1, first_line2 }); printSecondLine(); } diff --git a/exercises/064_builtins.zig b/exercises/064_builtins.zig index 508f8ed..018bf95 100644 --- a/exercises/064_builtins.zig +++ b/exercises/064_builtins.zig @@ -41,22 +41,38 @@ pub fn main() void { var my_result: u4 = undefined; var overflowed: bool = undefined; overflowed = @addWithOverflow(u4, a, b, &my_result); - // + + // Check out our fancy formatting! b:0>4 means, "print + // as a binary number, zero-pad right-aligned four digits." // The print() below will produce: "1101 + 0101 = 0010 (true)". - // Let's make sense of this answer by counting up from 1101: + print("{b:0>4} + {b:0>4} = {b:0>4} ({})", .{ a, b, my_result, overflowed }); + + // Let's make sense of this answer. The value of 'b' in decimal is 5. + // Let's add 5 to 'a' but go one by one and see where it overflows: // - // Overflowed? - // 1101 + 1 = 1110 No. - // 1110 + 1 = 1111 No. - // 1111 + 1 = 0000 Yes! (Real answer is 10000) - // 0000 + 1 = 0001 No. - // 0001 + 1 = 0010 No. + // a | b | result | overflowed? + // ---------------------------------- + // 1101 + 0001 = 1110 | false + // 1110 + 0001 = 1111 | false + // 1111 + 0001 = 0000 | true (the real answer is 10000) + // 0000 + 0001 = 0001 | false + // 0001 + 0001 = 0010 | false // - // Also, check out our fancy formatting! b:0>4 means, "print - // as a binary number, zero-pad right-aligned four digits." - print("{b:0>4} + {b:0>4} = {b:0>4} ({})", .{ a, b, my_result, overflowed }); + // In the last two lines the value of 'a' is corrupted because there was + // an overflow in line 3, but the operations of lines 4 and 5 themselves + // do not overflow. + // There is a difference between + // - a value, that overflowed at some point and is now corrupted + // - a single operation that overflows and maybe causes subsequent errors + // In practise we usually notice the overflowed value first and have to work + // our way backwards to the operation that caused the overflow. + // + // If there was no overflow at all while adding 5 to a, what value would + // 'my_result' hold? Write the answer in into 'expected_result'. + const expected_result: u8 = ???; + print(". Without overflow: {b:0>8}. ", .{expected_result}); - print(". Furthermore, ", .{}); + print("Furthermore, ", .{}); // Here's a fun one: // diff --git a/exercises/065_builtins2.zig b/exercises/065_builtins2.zig index 1532c2a..d50b6f0 100644 --- a/exercises/065_builtins2.zig +++ b/exercises/065_builtins2.zig @@ -121,7 +121,7 @@ pub fn main() void { // Alas, we can't use a regular 'for' loop here because // 'fields' can only be evaluated at compile time. It seems // like we're overdue to learn about this "comptime" stuff, - // isn't it? :-) + // doesn't it? :-) print(".\n", .{}); } diff --git a/exercises/079_quoted_identifiers.zig b/exercises/079_quoted_identifiers.zig index 9ef22b0..182c7ff 100644 --- a/exercises/079_quoted_identifiers.zig +++ b/exercises/079_quoted_identifiers.zig @@ -22,7 +22,7 @@ const print = @import("std").debug.print; pub fn main() void { const 55_cows: i32 = 55; const isn't true: bool = false; - + print("Sweet freedom: {}, {}.\n", .{ 55_cows, isn't true, diff --git a/exercises/082_anonymous_structs3.zig b/exercises/082_anonymous_structs3.zig index 1214589..8344321 100644 --- a/exercises/082_anonymous_structs3.zig +++ b/exercises/082_anonymous_structs3.zig @@ -116,7 +116,7 @@ fn printTuple(tuple: anytype) void { // @field(foo, "x"); // returns the value at foo.x // // The first field should print as: "0"(bool):true - print("\"{s}\"({s}):{any} ", .{ + print("\"{s}\"({any}):{any} ", .{ field.???, field.???, ???, diff --git a/patches/patches/064_builtins.patch b/patches/patches/064_builtins.patch index 644128b..06fa735 100644 --- a/patches/patches/064_builtins.patch +++ b/patches/patches/064_builtins.patch @@ -1,4 +1,8 @@ 72c72 +< const expected_result: u8 = ???; +--- +> const expected_result: u8 = 0b00010010; +88c88 < const tupni: u8 = @bitReverse(input); --- > const tupni: u8 = @bitReverse(u8, input); |