From e58f155bd6261a0c1408e8bb3b177bbced828eb3 Mon Sep 17 00:00:00 2001 From: Will Clardy Date: Mon, 15 Feb 2021 16:55:19 -0500 Subject: Manually apply `zig fmt` style to comments --- exercises/09_if.zig | 2 +- exercises/11_while.zig | 2 +- exercises/13_while3.zig | 4 ++-- exercises/14_while4.zig | 4 ++-- exercises/18_functions.zig | 2 +- exercises/19_functions2.zig | 2 +- exercises/30_switch.zig | 2 -- 7 files changed, 8 insertions(+), 10 deletions(-) diff --git a/exercises/09_if.zig b/exercises/09_if.zig index a472e48..284563d 100644 --- a/exercises/09_if.zig +++ b/exercises/09_if.zig @@ -11,7 +11,7 @@ // // a == b means "a equals b" // a < b means "a is less than b" -// a !=b means "a does not equal b" +// a != b means "a does not equal b" // // The important thing about Zig's "if" is that it *only* accepts // boolean values. It won't coerce numbers or other types of data diff --git a/exercises/11_while.zig b/exercises/11_while.zig index 4c4fc4f..9693593 100644 --- a/exercises/11_while.zig +++ b/exercises/11_while.zig @@ -13,7 +13,7 @@ // a == b means "a equals b" // a < b means "a is less than b" // a > b means "a is greater than b" -// a !=b means "a does not equal b" +// a != b means "a does not equal b" // const std = @import("std"); diff --git a/exercises/13_while3.zig b/exercises/13_while3.zig index 3ff42ff..778dbba 100644 --- a/exercises/13_while3.zig +++ b/exercises/13_while3.zig @@ -5,9 +5,9 @@ // // Example: // -// while (condition) : (continue expression){ +// while (condition) : (continue expression) { // -// if(other condition) continue; +// if (other condition) continue; // // } // diff --git a/exercises/14_while4.zig b/exercises/14_while4.zig index a28b9a9..c8dfc2e 100644 --- a/exercises/14_while4.zig +++ b/exercises/14_while4.zig @@ -1,9 +1,9 @@ // // You can force a loop to exit immediately with a "break" statement: // -// while (condition) : (continue expression){ +// while (condition) : (continue expression) { // -// if(other condition) break; +// if (other condition) break; // // } // diff --git a/exercises/18_functions.zig b/exercises/18_functions.zig index bda90cd..2dbb8eb 100644 --- a/exercises/18_functions.zig +++ b/exercises/18_functions.zig @@ -3,7 +3,7 @@ // writing one of our own: // // fn foo(n: u8) u8 { -// return n+1; +// return n + 1; // } // // The foo() function above takes a number "n" and returns a number that is diff --git a/exercises/19_functions2.zig b/exercises/19_functions2.zig index 99319c3..c323be8 100644 --- a/exercises/19_functions2.zig +++ b/exercises/19_functions2.zig @@ -3,7 +3,7 @@ // example that takes two parameters. As you can see, parameters // are declared just like any other types ("name": "type"): // -// fn myFunction( number: u8, is_lucky: bool ) { +// fn myFunction(number: u8, is_lucky: bool) { // ... // } // diff --git a/exercises/30_switch.zig b/exercises/30_switch.zig index b10ad14..451060e 100644 --- a/exercises/30_switch.zig +++ b/exercises/30_switch.zig @@ -22,8 +22,6 @@ // return GameError.TooManyPlayers; // } // -// -// const std = @import("std"); pub fn main() void { -- cgit v1.2.3-ZIG From 2f821bd5e83129445179ea7bd81260df74fff295 Mon Sep 17 00:00:00 2001 From: Will Clardy Date: Mon, 15 Feb 2021 16:55:44 -0500 Subject: Apply `zig fmt` to exercises --- exercises/01_hello.zig | 3 +-- exercises/03_assignment.zig | 4 ++-- exercises/04_arrays.zig | 5 +++-- exercises/06_strings.zig | 5 ++--- exercises/07_strings2.zig | 6 +++--- exercises/10_if2.zig | 1 - exercises/11_while.zig | 2 +- exercises/13_while3.zig | 6 +++--- exercises/14_while4.zig | 4 ++-- exercises/15_for.zig | 7 +++---- exercises/17_quiz2.zig | 4 ++-- exercises/18_functions.zig | 3 +-- exercises/19_functions2.zig | 3 +-- exercises/20_quiz3.zig | 6 ++---- exercises/21_errors.zig | 10 +++++----- exercises/22_errors2.zig | 3 +-- exercises/23_errors3.zig | 6 +++--- exercises/24_errors4.zig | 13 +++++++------ exercises/25_errors5.zig | 6 ++---- exercises/28_defer2.zig | 16 ++++++++++++---- exercises/29_errdefer.zig | 9 ++++----- exercises/30_switch.zig | 20 ++++++++++---------- exercises/31_switch2.zig | 18 +++++++++--------- exercises/32_unreachable.zig | 14 ++++++++++---- exercises/33_iferror.zig | 8 ++++---- exercises/34_quiz4.zig | 4 ++-- exercises/35_enums.zig | 20 +++++++++++++------- exercises/36_enums2.zig | 18 +++++++++--------- exercises/37_structs.zig | 10 +++++----- exercises/38_structs2.zig | 17 +++++++++-------- exercises/39_pointers.zig | 6 +++--- exercises/40_pointers2.zig | 4 ++-- exercises/41_pointers3.zig | 6 +++--- exercises/42_pointers4.zig | 1 - exercises/43_pointers5.zig | 19 +++++++++---------- exercises/44_quiz5.zig | 6 +++--- exercises/45_optionals.zig | 3 +-- 37 files changed, 152 insertions(+), 144 deletions(-) diff --git a/exercises/01_hello.zig b/exercises/01_hello.zig index 8d26940..d2093c7 100644 --- a/exercises/01_hello.zig +++ b/exercises/01_hello.zig @@ -2,7 +2,7 @@ // Oh no! This program is supposed to print "Hello world!" but it needs // your help! // -// +// // Zig functions are private by default but the main() function should // be public. // @@ -19,4 +19,3 @@ const std = @import("std"); fn main() void { std.debug.print("Hello world!\n", .{}); } - diff --git a/exercises/03_assignment.zig b/exercises/03_assignment.zig index 3775afc..6a4364b 100644 --- a/exercises/03_assignment.zig +++ b/exercises/03_assignment.zig @@ -24,7 +24,7 @@ // const bar: u16 = 2000; // // 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 // @@ -47,5 +47,5 @@ pub fn main() void { // is a string. The string may contain placeholders '{}', and the // second parameter is an "anonymous list literal" (don't worry // about this for now!) with the values to be printed. - std.debug.print("{} {} {}\n", .{n, pi, negative_eleven}); + std.debug.print("{} {} {}\n", .{ n, pi, negative_eleven }); } diff --git a/exercises/04_arrays.zig b/exercises/04_arrays.zig index c1e9fd9..88fcc78 100644 --- a/exercises/04_arrays.zig +++ b/exercises/04_arrays.zig @@ -46,6 +46,7 @@ pub fn main() void { // Use the len property to get the length of the array: const length = some_primes.???; - std.debug.print("First: {}, Fourth: {}, Length: {}\n", - .{first, fourth, length}); + std.debug.print("First: {}, Fourth: {}, Length: {}\n", .{ + first, fourth, length, + }); } diff --git a/exercises/06_strings.zig b/exercises/06_strings.zig index 1d3da1a..a58b9ef 100644 --- a/exercises/06_strings.zig +++ b/exercises/06_strings.zig @@ -1,6 +1,6 @@ // // Now that we've learned about arrays, we can talk about strings. -// +// // We've already seen Zig string literals: "Hello world.\n" // // Zig stores strings as arrays of bytes. @@ -33,8 +33,7 @@ pub fn main() void { const major_tom = major ??? tom; // That's all the problems. Let's see our results: - std.debug.print("d={u} {s}{s}\n",.{d, laugh, major_tom}); - // + std.debug.print("d={u} {s}{s}\n", .{ d, laugh, major_tom }); // Keen eyes will notice that we've put 'u' and 's' inside the '{}' // placeholders in the format string above. This tells the // print() function to format the values as a UTF-8 character and diff --git a/exercises/07_strings2.zig b/exercises/07_strings2.zig index f0bbf99..6350be1 100644 --- a/exercises/07_strings2.zig +++ b/exercises/07_strings2.zig @@ -8,17 +8,17 @@ // \\Line One // \\Line Two // ; -// +// // See if you can make this program print some song lyrics. // const std = @import("std"); pub fn main() void { - const lyrics = + const lyrics = Ziggy played guitar Jamming good with Andrew Kelley And the Spiders from Mars ; - std.debug.print("{s}\n",.{lyrics}); + std.debug.print("{s}\n", .{lyrics}); } diff --git a/exercises/10_if2.zig b/exercises/10_if2.zig index ba9c2df..d0c8cac 100644 --- a/exercises/10_if2.zig +++ b/exercises/10_if2.zig @@ -14,4 +14,3 @@ pub fn main() void { std.debug.print("With the discount, the price is ${}.\n", .{price}); } - diff --git a/exercises/11_while.zig b/exercises/11_while.zig index 9693593..674d904 100644 --- a/exercises/11_while.zig +++ b/exercises/11_while.zig @@ -21,7 +21,7 @@ pub fn main() void { var n: u32 = 2; // Please use a condition that is true UNTIL "n" reaches 1024: - while ( ??? ){ + while (???) { // Print the current number std.debug.print("{} ", .{n}); diff --git a/exercises/13_while3.zig b/exercises/13_while3.zig index 778dbba..4cccf62 100644 --- a/exercises/13_while3.zig +++ b/exercises/13_while3.zig @@ -21,11 +21,11 @@ pub fn main() void { // I want to print every number between 1 and 20 that is NOT // divisible by 3 or 5. - while (n <= 20) : (n+=1) { + while (n <= 20) : (n += 1) { // The '%' symbol is the "modulo" operator and it // returns the remainder after division. - if(n % 3 == 0) ???; - if(n % 5 == 0) ???; + if (n % 3 == 0) ???; + if (n % 5 == 0) ???; std.debug.print("{} ", .{n}); } diff --git a/exercises/14_while4.zig b/exercises/14_while4.zig index c8dfc2e..7b2714e 100644 --- a/exercises/14_while4.zig +++ b/exercises/14_while4.zig @@ -17,8 +17,8 @@ pub fn main() void { // Oh dear! This while loop will go forever!? // Please fix this so the print statement below gives the desired output. - while (true) : (n+=1) { - if(???) ???; + while (true) : (n += 1) { + if (???) ???; } // Result: we want n=4 diff --git a/exercises/15_for.zig b/exercises/15_for.zig index 652478b..2ce930e 100644 --- a/exercises/15_for.zig +++ b/exercises/15_for.zig @@ -16,13 +16,12 @@ pub fn main() void { std.debug.print("A Dramatic Story: ", .{}); for (???) |???| { - if(scene == 'h') std.debug.print(":-) ", .{}); - if(scene == 's') std.debug.print(":-( ", .{}); - if(scene == 'n') std.debug.print(":-| ", .{}); + if (scene == 'h') std.debug.print(":-) ", .{}); + if (scene == 's') std.debug.print(":-( ", .{}); + if (scene == 'n') std.debug.print(":-| ", .{}); } std.debug.print("The End.\n", .{}); } -// // Note that "for" loops also work on things called "slices" // which we'll see later. diff --git a/exercises/17_quiz2.zig b/exercises/17_quiz2.zig index 339f733..7de7010 100644 --- a/exercises/17_quiz2.zig +++ b/exercises/17_quiz2.zig @@ -19,10 +19,10 @@ function main() void { ??? (i <= stop_at) : (i += 1) { if (i % 3 == 0) std.debug.print("Fizz", .{}); if (i % 5 == 0) std.debug.print("Buzz", .{}); - if ( !(i % 3 == 0) and !(i % 5 == 0) ) { + if (!(i % 3 == 0) and !(i % 5 == 0)) { std.debug.print("{}", .{???}); } std.debug.print(", ", .{}); } - std.debug.print("\n",.{}); + std.debug.print("\n", .{}); } diff --git a/exercises/18_functions.zig b/exercises/18_functions.zig index 2dbb8eb..51be2cd 100644 --- a/exercises/18_functions.zig +++ b/exercises/18_functions.zig @@ -19,11 +19,10 @@ const std = @import("std"); pub fn main() void { // The new function deepThought() should return the number 42. See below. const answer: u8 = deepThought(); - + std.debug.print("Answer to the Ultimate Question: {}\n", .{answer}); } -// // Please define the deepThought() function below. // // We're just missing a couple things. One thing we're NOT missing is the diff --git a/exercises/19_functions2.zig b/exercises/19_functions2.zig index c323be8..00f33c5 100644 --- a/exercises/19_functions2.zig +++ b/exercises/19_functions2.zig @@ -7,7 +7,7 @@ // ... // } // -const std = @import( "std" ); +const std = @import("std"); pub fn main() void { std.debug.print("Powers of two: {} {} {} {}\n", .{ @@ -18,7 +18,6 @@ pub fn main() void { }); } -// // Please give this function the correct input parameter(s). // You'll need to figure out the parameter name and type that we're // expecting. The output type has already been specified for you. diff --git a/exercises/20_quiz3.zig b/exercises/20_quiz3.zig index e18ef37..651af8c 100644 --- a/exercises/20_quiz3.zig +++ b/exercises/20_quiz3.zig @@ -5,16 +5,15 @@ // // Both of these are simply labeled "loop" below. // -const std = @import( "std" ); +const std = @import("std"); pub fn main() void { - const my_numbers = [4]u16{ 5,6,7,8 }; + const my_numbers = [4]u16{ 5, 6, 7, 8 }; printPowersOfTwo(my_numbers); std.debug.print("\n", .{}); } -// // You won't see this every day: a function that takes an array with // exactly four u16 numbers. This is not how you would normally pass // an array to a function. We'll learn about slices and pointers in @@ -28,7 +27,6 @@ fn printPowersOfTwo(numbers: [4]u16) ??? { } } -// // This function bears a striking resemblance to twoToThe() in the last // exercise. But don't be fooled! This one does the math without the aid // of the standard library! diff --git a/exercises/21_errors.zig b/exercises/21_errors.zig index 7714c4b..cbb5ac8 100644 --- a/exercises/21_errors.zig +++ b/exercises/21_errors.zig @@ -4,7 +4,7 @@ // In Zig, an error is a value. Errors are named so we can identify // things that can go wrong. Errors are created in "error sets", which // are just a collection of named errors. -// +// // We have the start of an error set, but we're missing the condition // "TooSmall". Please add it where needed! const MyNumberError = error{ @@ -16,13 +16,13 @@ const MyNumberError = error{ const std = @import("std"); pub fn main() void { - var nums = [_]u8{2,3,4,5,6}; + var nums = [_]u8{ 2, 3, 4, 5, 6 }; for (nums) |n| { std.debug.print("{}", .{n}); const number_error = numberFail(n); - + if (number_error == MyNumberError.TooBig) { std.debug.print(">4. ", .{}); } @@ -40,7 +40,7 @@ pub fn main() void { // Notice how this function can return any member of the MyNumberError // error set. fn numberFail(n: u8) MyNumberError { - if(n > 4) return MyNumberError.TooBig; - if(n < 4) return MyNumberError.TooSmall; // <---- this one is free! + if (n > 4) return MyNumberError.TooBig; + if (n < 4) return MyNumberError.TooSmall; // <---- this one is free! return MyNumberError.TooFour; } diff --git a/exercises/22_errors2.zig b/exercises/22_errors2.zig index 7675d2d..fa0eafa 100644 --- a/exercises/22_errors2.zig +++ b/exercises/22_errors2.zig @@ -16,7 +16,7 @@ // const std = @import("std"); -const MyNumberError = error{ TooSmall }; +const MyNumberError = error{TooSmall}; pub fn main() void { var my_number: ??? = 5; @@ -27,4 +27,3 @@ pub fn main() void { std.debug.print("I compiled!", .{}); } - diff --git a/exercises/23_errors3.zig b/exercises/23_errors3.zig index 6060bf1..a465737 100644 --- a/exercises/23_errors3.zig +++ b/exercises/23_errors3.zig @@ -8,13 +8,13 @@ // const std = @import("std"); -const MyNumberError = error{ TooSmall }; +const MyNumberError = error{TooSmall}; pub fn main() void { var a: u32 = addTwenty(44) catch 22; - var b: u32 = addTwenty(4) ??? 22; + var b: u32 = addTwenty(4) ??? 22; - std.debug.print("a={}, b={}", .{a,b}); + std.debug.print("a={}, b={}", .{ a, b }); } // Please provide the return type from this function. diff --git a/exercises/24_errors4.zig b/exercises/24_errors4.zig index b60cc2d..560b129 100644 --- a/exercises/24_errors4.zig +++ b/exercises/24_errors4.zig @@ -23,9 +23,9 @@ pub fn main() void { // that makeJustRight() returns a error union (for now). var a: u32 = makeJustRight(44) catch 0; var b: u32 = makeJustRight(14) catch 0; - var c: u32 = makeJustRight(4) catch 0; + var c: u32 = makeJustRight(4) catch 0; - std.debug.print("a={}, b={}, c={}", .{a,b,c}); + std.debug.print("a={}, b={}, c={}", .{ a, b, c }); } // In this silly example we've split the responsibility of making @@ -37,7 +37,9 @@ pub fn main() void { // detectProblems() Returns the number or an error. // fn makeJustRight(n: u32) MyNumberError!u32 { - return fixTooBig(n) catch |err| { return err; }; + return fixTooBig(n) catch |err| { + return err; + }; } fn fixTooBig(n: u32) MyNumberError!u32 { @@ -45,14 +47,14 @@ fn fixTooBig(n: u32) MyNumberError!u32 { if (err == MyNumberError.TooBig) { return 20; } - + return err; }; } fn fixTooSmall(n: u32) MyNumberError!u32 { // Oh dear, this is missing a lot! But don't worry, it's nearly - // identical to fixTooBig() above. + // identical to fixTooBig() above. // // If we get a TooSmall error, we should return 10. // If we get any other error, we should return that error. @@ -65,4 +67,3 @@ fn detectProblems(n: u32) MyNumberError!u32 { if (n > 20) return MyNumberError.TooBig; return n; } - diff --git a/exercises/25_errors5.zig b/exercises/25_errors5.zig index 8b702cf..5119dcf 100644 --- a/exercises/25_errors5.zig +++ b/exercises/25_errors5.zig @@ -17,13 +17,12 @@ const MyNumberError = error{ pub fn main() void { var a: u32 = addFive(44) catch 0; var b: u32 = addFive(14) catch 0; - var c: u32 = addFive(4) catch 0; + var c: u32 = addFive(4) catch 0; - std.debug.print("a={}, b={}, c={}", .{a,b,c}); + std.debug.print("a={}, b={}, c={}", .{ a, b, c }); } fn addFive(n: u32) MyNumberError!u32 { - // // This function needs to return any error which might come back from detect(). // Please use a "try" statement rather than a "catch". // @@ -37,4 +36,3 @@ fn detect(n: u32) MyNumberError!u32 { if (n > 20) return MyNumberError.TooBig; return n; } - diff --git a/exercises/28_defer2.zig b/exercises/28_defer2.zig index 5c991da..6943012 100644 --- a/exercises/28_defer2.zig +++ b/exercises/28_defer2.zig @@ -9,7 +9,6 @@ pub fn main() void { for (animals) |a| printAnimal(a); - std.debug.print("done.\n", .{}); } @@ -21,9 +20,18 @@ fn printAnimal(animal: u8) void { std.debug.print(") ", .{}); // <---- how!? - if (animal == 'g'){ std.debug.print("Goat", .{}); return; } - if (animal == 'c'){ std.debug.print("Cat", .{}); return; } - if (animal == 'd'){ std.debug.print("Dog", .{}); return; } + if (animal == 'g') { + std.debug.print("Goat", .{}); + return; + } + if (animal == 'c') { + std.debug.print("Cat", .{}); + return; + } + if (animal == 'd') { + std.debug.print("Dog", .{}); + return; + } std.debug.print("Unknown", .{}); } diff --git a/exercises/29_errdefer.zig b/exercises/29_errdefer.zig index cd2158d..f43c738 100644 --- a/exercises/29_errdefer.zig +++ b/exercises/29_errdefer.zig @@ -15,7 +15,6 @@ // const std = @import("std"); -// var counter: u32 = 0; const MyErr = error{ GetFail, IncFail }; @@ -25,8 +24,8 @@ pub fn main() void { var a: u32 = makeNumber() catch return; var b: u32 = makeNumber() catch return; - std.debug.print("Numbers: {}, {}\n", .{a,b}); -} + std.debug.print("Numbers: {}, {}\n", .{ a, b }); +} fn makeNumber() MyErr!u32 { std.debug.print("Getting number...", .{}); @@ -35,7 +34,7 @@ fn makeNumber() MyErr!u32 { // function exits with an error: std.debug.print("failed!\n", .{}); - var num = try getNumber(); // <-- This could fail! + var num = try getNumber(); // <-- This could fail! num = try increaseNumber(num); // <-- This could ALSO fail! @@ -52,7 +51,7 @@ fn getNumber() MyErr!u32 { fn increaseNumber(n: u32) MyErr!u32 { // I fail after the first time you run me! if (counter > 0) return MyErr.IncFail; - + // Sneaky, weird global stuff. counter += 1; diff --git a/exercises/30_switch.zig b/exercises/30_switch.zig index 451060e..cb983f5 100644 --- a/exercises/30_switch.zig +++ b/exercises/30_switch.zig @@ -21,7 +21,7 @@ // alert(); // return GameError.TooManyPlayers; // } -// +// const std = @import("std"); pub fn main() void { @@ -29,15 +29,15 @@ pub fn main() void { for (lang_chars) |c| { switch (c) { - 1 => std.debug.print("A", .{}), - 2 => std.debug.print("B", .{}), - 3 => std.debug.print("C", .{}), - 4 => std.debug.print("D", .{}), - 5 => std.debug.print("E", .{}), - 6 => std.debug.print("F", .{}), - 7 => std.debug.print("G", .{}), - 8 => std.debug.print("H", .{}), - 9 => std.debug.print("I", .{}), + 1 => std.debug.print("A", .{}), + 2 => std.debug.print("B", .{}), + 3 => std.debug.print("C", .{}), + 4 => std.debug.print("D", .{}), + 5 => std.debug.print("E", .{}), + 6 => std.debug.print("F", .{}), + 7 => std.debug.print("G", .{}), + 8 => std.debug.print("H", .{}), + 9 => std.debug.print("I", .{}), 10 => std.debug.print("J", .{}), // ... we don't need everything in between ... 25 => std.debug.print("Y", .{}), diff --git a/exercises/31_switch2.zig b/exercises/31_switch2.zig index 138b809..b7680b4 100644 --- a/exercises/31_switch2.zig +++ b/exercises/31_switch2.zig @@ -16,15 +16,15 @@ pub fn main() void { for (lang_chars) |c| { var real_char: u8 = switch (c) { - 1 => 'A', - 2 => 'B', - 3 => 'C', - 4 => 'D', - 5 => 'E', - 6 => 'F', - 7 => 'G', - 8 => 'H', - 9 => 'I', + 1 => 'A', + 2 => 'B', + 3 => 'C', + 4 => 'D', + 5 => 'E', + 6 => 'F', + 7 => 'G', + 8 => 'H', + 9 => 'I', 10 => 'J', // ... 25 => 'Y', diff --git a/exercises/32_unreachable.zig b/exercises/32_unreachable.zig index c81efac..ffc35a4 100644 --- a/exercises/32_unreachable.zig +++ b/exercises/32_unreachable.zig @@ -16,7 +16,7 @@ // // WE know there are only three operations but Zig doesn't. Use the // unreachable statement to make the switch complete. Or ELSE. :-) -// +// const std = @import("std"); pub fn main() void { @@ -26,9 +26,15 @@ pub fn main() void { for (operations) |op| { switch (op) { - 1 => { current_value += 1; }, - 2 => { current_value -= 1; }, - 3 => { current_value *= current_value; }, + 1 => { + current_value += 1; + }, + 2 => { + current_value -= 1; + }, + 3 => { + current_value *= current_value; + }, } std.debug.print("{} ", .{current_value}); diff --git a/exercises/33_iferror.zig b/exercises/33_iferror.zig index ed92e94..67777a9 100644 --- a/exercises/33_iferror.zig +++ b/exercises/33_iferror.zig @@ -23,7 +23,7 @@ const MyNumberError = error{ const std = @import("std"); pub fn main() void { - var nums = [_]u8{2,3,4,5,6}; + var nums = [_]u8{ 2, 3, 4, 5, 6 }; for (nums) |num| { std.debug.print("{}", .{num}); @@ -32,7 +32,7 @@ pub fn main() void { if (n) |value| { std.debug.print("=4. ", .{}); } else |err| switch (err) { - MyNumberError.TooBig => std.debug.print(">4. ", .{}), + MyNumberError.TooBig => std.debug.print(">4. ", .{}), // Please add a match for TooSmall here and have it print: "<4. " } } @@ -43,7 +43,7 @@ pub fn main() void { // This time we'll have numberMaybeFail() return an error union rather // than a straight error. fn numberMaybeFail(n: u8) MyNumberError!u8 { - if(n > 4) return MyNumberError.TooBig; - if(n < 4) return MyNumberError.TooSmall; + if (n > 4) return MyNumberError.TooBig; + if (n < 4) return MyNumberError.TooSmall; return n; } diff --git a/exercises/34_quiz4.zig b/exercises/34_quiz4.zig index 43734b7..6b0e3fc 100644 --- a/exercises/34_quiz4.zig +++ b/exercises/34_quiz4.zig @@ -7,7 +7,7 @@ // const std = @import("std"); -const NumError = error{ IllegalNumber }; +const NumError = error{IllegalNumber}; pub fn main() void { const stdout = std.io.getStdOut().writer(); @@ -19,6 +19,6 @@ pub fn main() void { // Just don't modify this function. It's "perfect" the way it is. :-) fn getNumber() NumError!u32 { - if( false ) return NumError.IllegalNumber; + if (false) return NumError.IllegalNumber; return 42; } diff --git a/exercises/35_enums.zig b/exercises/35_enums.zig index cf455a4..1825f52 100644 --- a/exercises/35_enums.zig +++ b/exercises/35_enums.zig @@ -6,7 +6,7 @@ // 1. Having to remember op codes by number is no good. // 2. We had to use "unreachable" because Zig had no way of knowing // how many valid op codes there were. -// +// // An "enum" is a Zig construct that lets you give names to numeric // values and store them in a set. They look a lot like error sets: // @@ -16,11 +16,11 @@ // // Let's use an enum in place of the numbers we were using in the // previous version! -// +// const std = @import("std"); // Please complete the enum! -const Ops = enum{ ??? }; +const Ops = enum { ??? }; pub fn main() void { const operations = [_]Ops{ @@ -29,16 +29,22 @@ pub fn main() void { Ops.inc, Ops.pow, Ops.dec, - Ops.dec + Ops.dec, }; var current_value: u32 = 0; for (operations) |op| { switch (op) { - Ops.inc => { current_value += 1; }, - Ops.dec => { current_value -= 1; }, - Ops.pow => { current_value *= current_value; }, + Ops.inc => { + current_value += 1; + }, + Ops.dec => { + current_value -= 1; + }, + Ops.pow => { + current_value *= current_value; + }, // No "else" needed! Why is that? } diff --git a/exercises/36_enums2.zig b/exercises/36_enums2.zig index 2e04415..650abef 100644 --- a/exercises/36_enums2.zig +++ b/exercises/36_enums2.zig @@ -16,7 +16,7 @@ const std = @import("std"); // Zig lets us write integers in hexadecimal format: // -// 0xf (is the value 15 in hex) +// 0xf (is the value 15 in hex) // // Web browsers let us specify colors using a hexadecimal // number where each byte represents the brightness of the @@ -26,10 +26,10 @@ const std = @import("std"); // #RRGGBB // // Please define and use a pure blue value Color: -const Color = enum(u32){ - red = 0xff0000, +const Color = enum(u32) { + red = 0xff0000, green = 0x00ff00, - blue = ???, + blue = ???, }; pub fn main() void { @@ -53,9 +53,9 @@ pub fn main() void { \\ Green \\ Blue \\

- , .{ - @enumToInt(Color.red), - @enumToInt(Color.green), - @enumToInt(???), // Oops! We're missing something! - }); + , .{ + @enumToInt(Color.red), + @enumToInt(Color.green), + @enumToInt(???), // Oops! We're missing something! + }); } diff --git a/exercises/37_structs.zig b/exercises/37_structs.zig index dd4b633..37989c0 100644 --- a/exercises/37_structs.zig +++ b/exercises/37_structs.zig @@ -23,7 +23,7 @@ const std = @import("std"); // We'll use an enum to specify the character class. -const Class = enum{ +const Class = enum { wizard, thief, bard, @@ -32,7 +32,7 @@ const Class = enum{ // Please add a new property to this struct called "health" and make // it a u8 integer type. -const Character = struct{ +const Character = struct { class: Class, gold: u32, experience: u32, @@ -41,8 +41,8 @@ const Character = struct{ pub fn main() void { // Please initialize Glorp with 100 health. var glorp_the_wise = Character{ - .class = Class.wizard, - .gold = 20, + .class = Class.wizard, + .gold = 20, .experience = 10, }; @@ -54,6 +54,6 @@ pub fn main() void { std.debug.print("Your wizard has {} health and {} gold.", .{ glorp_the_wise.health, - glorp_the_wise.gold + glorp_the_wise.gold, }); } diff --git a/exercises/38_structs2.zig b/exercises/38_structs2.zig index b6def93..b0db022 100644 --- a/exercises/38_structs2.zig +++ b/exercises/38_structs2.zig @@ -2,20 +2,20 @@ // Grouping values in structs is not merely convenient. It also allows // us to treat the values as a single item when storing them, passing // them to functions, etc. -// +// // This exercise demonstrates how we can store structs in an array and // how doing so lets us print them all (both) using a loop. // const std = @import("std"); -const Class = enum{ +const Class = enum { wizard, thief, bard, warrior, }; -const Character = struct{ +const Character = struct { class: Class, gold: u32, health: u8, @@ -27,9 +27,9 @@ pub fn main() void { // Glorp the Wise chars[0] = Character{ - .class = Class.wizard, - .gold = 20, - .health = 100, + .class = Class.wizard, + .gold = 20, + .health = 100, .experience = 10, }; @@ -45,7 +45,8 @@ pub fn main() void { // Printing all RPG characters in a loop: for (chars) |c, num| { - std.debug.print("Character {} - G:{} H:{} XP:{}\n", - .{num+1, c.gold, c.health, c.experience}); + std.debug.print("Character {} - G:{} H:{} XP:{}\n", .{ + num + 1, c.gold, c.health, c.experience, + }); } } diff --git a/exercises/39_pointers.zig b/exercises/39_pointers.zig index 25b56c6..40b145c 100644 --- a/exercises/39_pointers.zig +++ b/exercises/39_pointers.zig @@ -3,7 +3,7 @@ // // var foo: u8 = 5; // foo is 5 // var bar: *u8 = &foo; // bar is a pointer -// +// // What is a pointer? It's a reference to a value. In this example // bar is a reference to the memory space that current contains the // value 5. @@ -16,7 +16,7 @@ // &foo a reference to foo // bar a pointer to the value at foo // bar.* the value 5 (the dereferenced value "at" bar) -// +// // We'll see why pointers are useful in a moment. For now, see if you // can make this example work! // @@ -32,5 +32,5 @@ pub fn main() void { // (See the "cheatsheet" above for ideas.) num2 = ???; - std.debug.print("num1: {}, num2: {}\n", .{num1, num2}); + std.debug.print("num1: {}, num2: {}\n", .{ num1, num2 }); } diff --git a/exercises/40_pointers2.zig b/exercises/40_pointers2.zig index b046dc1..43dd2c3 100644 --- a/exercises/40_pointers2.zig +++ b/exercises/40_pointers2.zig @@ -6,7 +6,7 @@ // // var foo: u8 = 5; // const bar: u8 = 5; -// +// // Then: // // &foo is of type "*u8" @@ -23,5 +23,5 @@ pub fn main() void { const a: u8 = 12; const b: *u8 = &a; // fix this! - std.debug.print("a: {}, b: {}\n", .{a, b.*}); + std.debug.print("a: {}, b: {}\n", .{ a, b.* }); } diff --git a/exercises/41_pointers3.zig b/exercises/41_pointers3.zig index 21a43bd..9e2bcc6 100644 --- a/exercises/41_pointers3.zig +++ b/exercises/41_pointers3.zig @@ -16,7 +16,7 @@ // var p4: *u8 = &unlocked; // const p5: *const u8 = &unlocked; // var p6: *const u8 = &unlocked; -// +// // Here p3 and p4 can both be used to change the value they point to but // p3 cannot point at anything else. // What's interesting is that p5 and p6 act like p1 and p2, but point to @@ -32,10 +32,10 @@ pub fn main() void { // Please define pointer "p" so that it can point to EITHER foo or // bar AND change the value it points to! ??? p: ??? = undefined; - + p = &foo; p.* += 1; p = &bar; p.* += 1; - std.debug.print("foo={}, bar={}\n", .{foo, bar}); + std.debug.print("foo={}, bar={}\n", .{ foo, bar }); } diff --git a/exercises/42_pointers4.zig b/exercises/42_pointers4.zig index e6b8964..261dbc1 100644 --- a/exercises/42_pointers4.zig +++ b/exercises/42_pointers4.zig @@ -12,7 +12,6 @@ pub fn main() void { makeFive(&num); std.debug.print("num: {}, ", .{num}); - // Now something interesting. Let's pass a reference to a // specific array value: makeFive(&more_nums[2]); diff --git a/exercises/43_pointers5.zig b/exercises/43_pointers5.zig index dc178ec..cb94189 100644 --- a/exercises/43_pointers5.zig +++ b/exercises/43_pointers5.zig @@ -34,33 +34,32 @@ // const std = @import("std"); -const Class = enum{ +const Class = enum { wizard, thief, bard, warrior, }; -const Character = struct{ +const Character = struct { class: Class, gold: u32, - health: u8 = 100, // <--- You can also fields a default value! + health: u8 = 100, // <--- You can also provide fields a default value! experience: u32, }; pub fn main() void { var glorp = Character{ - .class = Class.wizard, - .gold = 10, + .class = Class.wizard, + .gold = 10, .experience = 20, }; // FIX ME! // Please pass our Character "glorp" to printCharacter(): - printCharacter( ??? ); + printCharacter(???); } - // Note how this function's "c" parameter is a pointer to a Character struct. fn printCharacter(c: *Character) void { @@ -68,9 +67,9 @@ fn printCharacter(c: *Character) void { // don't have to write the full enum name. Zig understands that ".wizard" // means "Class.wizard" when we switch on a Class enum value: const class_name = switch (c.class) { - .wizard => "Wizard", - .thief => "Thief", - .bard => "Bard", + .wizard => "Wizard", + .thief => "Thief", + .bard => "Bard", .warrior => "Warrior", }; diff --git a/exercises/44_quiz5.zig b/exercises/44_quiz5.zig index 6ec0da9..88e0ff7 100644 --- a/exercises/44_quiz5.zig +++ b/exercises/44_quiz5.zig @@ -4,13 +4,13 @@ // // Are holding hands // By holding tails." -// +// // from Holding Hands // by Lenore M. Link -// +// const std = @import("std"); // single quotes -const Elephant = struct{ +const Elephant = struct { letter: u8, tail: *Elephant = undefined, visited: bool = false, diff --git a/exercises/45_optionals.zig b/exercises/45_optionals.zig index 815ba75..1327e4c 100644 --- a/exercises/45_optionals.zig +++ b/exercises/45_optionals.zig @@ -31,7 +31,7 @@ pub fn main() void { // integer value from deepThought() OR the number 42: var answer: u8 = result; - std.debug.print("The Ultimate Answer: {}.\n",.{answer}); + std.debug.print("The Ultimate Answer: {}.\n", .{answer}); } fn deepThought() ?u8 { @@ -39,7 +39,6 @@ fn deepThought() ?u8 { // But we'll leave this as-is. Sorry Deep Thought. return null; } -// // Blast from the past: // // Optionals are a lot like error union types which can either -- cgit v1.2.3-ZIG From 304489ca1f465b5456fa8c21dd0ae4e4c6c48617 Mon Sep 17 00:00:00 2001 From: Will Clardy Date: Mon, 15 Feb 2021 17:13:55 -0500 Subject: Add remaining patch files --- patches/patches/03_assignment.patch | 13 ++++++++++++- patches/patches/04_arrays.patch | 13 ++++++++++++- patches/patches/05_arrays2.patch | 9 ++++++++- patches/patches/06_strings.patch | 13 ++++++++++++- patches/patches/07_strings2.patch | 9 ++++++++- patches/patches/08_quiz.patch | 15 ++++++++++++++- patches/patches/09_if.patch | 5 ++++- patches/patches/10_if2.patch | 5 ++++- patches/patches/11_while.patch | 5 ++++- patches/patches/12_while2.patch | 5 ++++- patches/patches/13_while3.patch | 7 ++++++- patches/patches/14_while4.patch | 5 ++++- patches/patches/15_for.patch | 5 ++++- patches/patches/16_for2.patch | 5 ++++- patches/patches/17_quiz2.patch | 17 ++++++++++++++++- patches/patches/18_functions.patch | 5 ++++- patches/patches/19_functions2.patch | 5 ++++- patches/patches/20_quiz3.patch | 19 ++++++++++++++++++- patches/patches/21_errors.patch | 9 ++++++++- patches/patches/22_errors2.patch | 5 ++++- patches/patches/23_errors3.patch | 9 ++++++++- patches/patches/24_errors4.patch | 11 ++++++++++- patches/patches/25_errors5.patch | 5 ++++- patches/patches/26_hello2.patch | 5 ++++- patches/patches/27_defer.patch | 5 ++++- patches/patches/28_defer2.patch | 5 ++++- patches/patches/29_errdefer.patch | 5 ++++- patches/patches/30_switch.patch | 3 ++- patches/patches/31_switch2.patch | 3 ++- patches/patches/32_unreachable.patch | 3 ++- patches/patches/33_iferror.patch | 3 ++- patches/patches/34_quiz4.patch | 9 ++++++++- patches/patches/35_enums.patch | 5 ++++- patches/patches/36_enums2.patch | 13 ++++++++++++- patches/patches/37_structs.patch | 5 ++++- patches/patches/38_structs2.patch | 8 +++++++- patches/patches/39_pointers.patch | 5 ++++- patches/patches/40_pointers2.patch | 5 ++++- patches/patches/41_pointers3.patch | 5 ++++- patches/patches/42_pointers4.patch | 5 ++++- patches/patches/43_pointers5.patch | 5 ++++- patches/patches/44_quiz5.patch | 5 ++++- patches/patches/45_optionals.patch | 5 ++++- 43 files changed, 263 insertions(+), 43 deletions(-) diff --git a/patches/patches/03_assignment.patch b/patches/patches/03_assignment.patch index 8b13789..bef4b24 100644 --- a/patches/patches/03_assignment.patch +++ b/patches/patches/03_assignment.patch @@ -1 +1,12 @@ - +37c37 +< const n: u8 = 50; +--- +> var n: u8 = 50; +40c40 +< const pi: u8 = 314159; +--- +> const pi: u32 = 314159; +42c42 +< const negative_eleven: u8 = -11; +--- +> const negative_eleven: i8 = -11; diff --git a/patches/patches/04_arrays.patch b/patches/patches/04_arrays.patch index 8b13789..c6f9de3 100644 --- a/patches/patches/04_arrays.patch +++ b/patches/patches/04_arrays.patch @@ -1 +1,12 @@ - +30c30 +< const some_primes = [_]u8{ 1, 3, 5, 7, 11, 13, 17, 19 }; +--- +> var some_primes = [_]u8{ 1, 3, 5, 7, 11, 13, 17, 19 }; +43c43 +< const fourth = some_primes[???]; +--- +> const fourth = some_primes[3]; +47c47 +< const length = some_primes.???; +--- +> const length = some_primes.len; diff --git a/patches/patches/05_arrays2.patch b/patches/patches/05_arrays2.patch index 8b13789..1e7b6b1 100644 --- a/patches/patches/05_arrays2.patch +++ b/patches/patches/05_arrays2.patch @@ -1 +1,8 @@ - +23c23 +< const leet = ???; +--- +> const leet = le ++ et; +28c28 +< const bit_pattern = [_]u8{ ??? } ** 3; +--- +> const bit_pattern = [_]u8{ 1, 0, 0, 1 } ** 3; diff --git a/patches/patches/06_strings.patch b/patches/patches/06_strings.patch index 8b13789..040a73c 100644 --- a/patches/patches/06_strings.patch +++ b/patches/patches/06_strings.patch @@ -1 +1,12 @@ - +22c22 +< const d: u8 = ziggy[???]; +--- +> const d: u8 = ziggy[4]; +26c26 +< const laugh = "ha " ???; +--- +> const laugh = "ha " ** 3; +33c33 +< const major_tom = major ??? tom; +--- +> const major_tom = major ++ " " ++ tom; diff --git a/patches/patches/07_strings2.patch b/patches/patches/07_strings2.patch index 8b13789..34cd053 100644 --- a/patches/patches/07_strings2.patch +++ b/patches/patches/07_strings2.patch @@ -1 +1,8 @@ - +18,20c18,20 +< Ziggy played guitar +< Jamming good with Andrew Kelley +< And the Spiders from Mars +--- +> \\Ziggy played guitar +> \\Jamming good with Andrew Kelley +> \\And the Spiders from Mars diff --git a/patches/patches/08_quiz.patch b/patches/patches/08_quiz.patch index 8b13789..3d35a5a 100644 --- a/patches/patches/08_quiz.patch +++ b/patches/patches/08_quiz.patch @@ -1 +1,14 @@ - +16c16 +< const x: u8 = 1; +--- +> var x: u8 = 1; +27c27 +< lang[???] = letters[x]; +--- +> lang[1] = letters[x]; +29,30c29,30 +< x = ???; +< lang[2] = letters[???]; +--- +> x = 5; +> lang[2] = letters[x]; diff --git a/patches/patches/09_if.patch b/patches/patches/09_if.patch index 8b13789..46579ad 100644 --- a/patches/patches/09_if.patch +++ b/patches/patches/09_if.patch @@ -1 +1,4 @@ - +26c26 +< if (foo) { +--- +> if (foo == 1) { diff --git a/patches/patches/10_if2.patch b/patches/patches/10_if2.patch index 8b13789..e78f644 100644 --- a/patches/patches/10_if2.patch +++ b/patches/patches/10_if2.patch @@ -1 +1,4 @@ - +13c13 +< var price: u8 = if ???; +--- +> var price: u8 = if (discount) 17 else 20; diff --git a/patches/patches/11_while.patch b/patches/patches/11_while.patch index 8b13789..a892191 100644 --- a/patches/patches/11_while.patch +++ b/patches/patches/11_while.patch @@ -1 +1,4 @@ - +24c24 +< while (???) { +--- +> while (n < 1024) { diff --git a/patches/patches/12_while2.patch b/patches/patches/12_while2.patch index 8b13789..29ae763 100644 --- a/patches/patches/12_while2.patch +++ b/patches/patches/12_while2.patch @@ -1 +1,4 @@ - +28c28 +< while (n < 1000) : ??? { +--- +> while (n < 1000) : (n *= 2) { diff --git a/patches/patches/13_while3.patch b/patches/patches/13_while3.patch index 8b13789..b0172da 100644 --- a/patches/patches/13_while3.patch +++ b/patches/patches/13_while3.patch @@ -1 +1,6 @@ - +27,28c27,28 +< if (n % 3 == 0) ???; +< if (n % 5 == 0) ???; +--- +> if (n % 3 == 0) continue; +> if (n % 5 == 0) continue; diff --git a/patches/patches/14_while4.patch b/patches/patches/14_while4.patch index 8b13789..fb67587 100644 --- a/patches/patches/14_while4.patch +++ b/patches/patches/14_while4.patch @@ -1 +1,4 @@ - +21c21 +< if (???) ???; +--- +> if (n == 4) break; diff --git a/patches/patches/15_for.patch b/patches/patches/15_for.patch index 8b13789..e937221 100644 --- a/patches/patches/15_for.patch +++ b/patches/patches/15_for.patch @@ -1 +1,4 @@ - +18c18 +< for (???) |???| { +--- +> for (story) |scene| { diff --git a/patches/patches/16_for2.patch b/patches/patches/16_for2.patch index 8b13789..5aba37f 100644 --- a/patches/patches/16_for2.patch +++ b/patches/patches/16_for2.patch @@ -1 +1,4 @@ - +27c27 +< for (bits) |bit, ???| { +--- +> for (bits) |bit, i| { diff --git a/patches/patches/17_quiz2.patch b/patches/patches/17_quiz2.patch index 8b13789..b46dab6 100644 --- a/patches/patches/17_quiz2.patch +++ b/patches/patches/17_quiz2.patch @@ -1 +1,16 @@ - +12c12 +< const std = import standard library; +--- +> const std = @import("std"); +14c14 +< function main() void { +--- +> pub fn main() void { +19c19 +< ??? (i <= stop_at) : (i += 1) { +--- +> while (i <= stop_at) : (i += 1) { +23c23 +< std.debug.print("{}", .{???}); +--- +> std.debug.print("{}", .{i}); diff --git a/patches/patches/18_functions.patch b/patches/patches/18_functions.patch index 8b13789..dd3f2f6 100644 --- a/patches/patches/18_functions.patch +++ b/patches/patches/18_functions.patch @@ -1 +1,4 @@ - +31c31 +< ??? deepThought() ??? { +--- +> fn deepThought() u8 { diff --git a/patches/patches/19_functions2.patch b/patches/patches/19_functions2.patch index 8b13789..254889a 100644 --- a/patches/patches/19_functions2.patch +++ b/patches/patches/19_functions2.patch @@ -1 +1,4 @@ - +25c25 +< fn twoToThe(???) u32 { +--- +> fn twoToThe(my_number: u32) u32 { diff --git a/patches/patches/20_quiz3.patch b/patches/patches/20_quiz3.patch index 8b13789..6a00d31 100644 --- a/patches/patches/20_quiz3.patch +++ b/patches/patches/20_quiz3.patch @@ -1 +1,18 @@ - +24,25c24,25 +< fn printPowersOfTwo(numbers: [4]u16) ??? { +< loop (numbers) |n| { +--- +> fn printPowersOfTwo(numbers: [4]u16) void { +> for (numbers) |n| { +34c34 +< fn twoToThe(number: u16) ??? { +--- +> fn twoToThe(number: u16) u16 { +38c38 +< loop (n < number) : (n += 1) { +--- +> while (n < number) : (n += 1) { +42c42 +< return ???; +--- +> return total; diff --git a/patches/patches/21_errors.patch b/patches/patches/21_errors.patch index 8b13789..b37b3c8 100644 --- a/patches/patches/21_errors.patch +++ b/patches/patches/21_errors.patch @@ -1 +1,8 @@ - +12c12 +< ???, +--- +> TooSmall, +29c29 +< if (???) { +--- +> if (number_error == MyNumberError.TooSmall) { diff --git a/patches/patches/22_errors2.patch b/patches/patches/22_errors2.patch index 8b13789..0501159 100644 --- a/patches/patches/22_errors2.patch +++ b/patches/patches/22_errors2.patch @@ -1 +1,4 @@ - +22c22 +< var my_number: ??? = 5; +--- +> var my_number: MyNumberError!u8 = 5; diff --git a/patches/patches/23_errors3.patch b/patches/patches/23_errors3.patch index 8b13789..a850116 100644 --- a/patches/patches/23_errors3.patch +++ b/patches/patches/23_errors3.patch @@ -1 +1,8 @@ - +15c15 +< var b: u32 = addTwenty(4) ??? 22; +--- +> var b: u32 = addTwenty(4) catch 22; +22c22 +< fn addTwenty(n: u32) ??? { +--- +> fn addTwenty(n: u32) MyNumberError!u32 { diff --git a/patches/patches/24_errors4.patch b/patches/patches/24_errors4.patch index 8b13789..bb3fc8f 100644 --- a/patches/patches/24_errors4.patch +++ b/patches/patches/24_errors4.patch @@ -1 +1,10 @@ - +62c62,68 +< return detectProblems(n) ??? +--- +> return detectProblems(n) catch |err| { +> if (err == MyNumberError.TooSmall) { +> return 10; +> } +> +> return err; +> }; diff --git a/patches/patches/25_errors5.patch b/patches/patches/25_errors5.patch index 8b13789..8aa59d4 100644 --- a/patches/patches/25_errors5.patch +++ b/patches/patches/25_errors5.patch @@ -1 +1,4 @@ - +29c29 +< var x = detect(n); +--- +> var x = try detect(n); diff --git a/patches/patches/26_hello2.patch b/patches/patches/26_hello2.patch index 8b13789..0065da5 100644 --- a/patches/patches/26_hello2.patch +++ b/patches/patches/26_hello2.patch @@ -1 +1,4 @@ - +22c22 +< stdout.print("Hello world!\n", .{}); +--- +> try stdout.print("Hello world!\n", .{}); diff --git a/patches/patches/27_defer.patch b/patches/patches/27_defer.patch index 8b13789..6ff7f98 100644 --- a/patches/patches/27_defer.patch +++ b/patches/patches/27_defer.patch @@ -1 +1,4 @@ - +23c23 +< std.debug.print("Two\n", .{}); +--- +> defer std.debug.print("Two\n", .{}); diff --git a/patches/patches/28_defer2.patch b/patches/patches/28_defer2.patch index 8b13789..c042c45 100644 --- a/patches/patches/28_defer2.patch +++ b/patches/patches/28_defer2.patch @@ -1 +1,4 @@ - +21c21 +< std.debug.print(") ", .{}); // <---- how!? +--- +> defer std.debug.print(") ", .{}); // <---- how!? diff --git a/patches/patches/29_errdefer.patch b/patches/patches/29_errdefer.patch index 8b13789..f93c56f 100644 --- a/patches/patches/29_errdefer.patch +++ b/patches/patches/29_errdefer.patch @@ -1 +1,4 @@ - +35c34 +< std.debug.print("failed!\n", .{}); +--- +> errdefer std.debug.print("failed!\n", .{}); diff --git a/patches/patches/30_switch.patch b/patches/patches/30_switch.patch index 8b13789..05cbe1a 100644 --- a/patches/patches/30_switch.patch +++ b/patches/patches/30_switch.patch @@ -1 +1,2 @@ - +48a49 +> else => std.debug.print("?", .{}), diff --git a/patches/patches/31_switch2.patch b/patches/patches/31_switch2.patch index 8b13789..f786762 100644 --- a/patches/patches/31_switch2.patch +++ b/patches/patches/31_switch2.patch @@ -1 +1,2 @@ - +33a34 +> else => '!', diff --git a/patches/patches/32_unreachable.patch b/patches/patches/32_unreachable.patch index 8b13789..0883932 100644 --- a/patches/patches/32_unreachable.patch +++ b/patches/patches/32_unreachable.patch @@ -1 +1,2 @@ - +37a38 +> else => unreachable, diff --git a/patches/patches/33_iferror.patch b/patches/patches/33_iferror.patch index 8b13789..62904db 100644 --- a/patches/patches/33_iferror.patch +++ b/patches/patches/33_iferror.patch @@ -1 +1,2 @@ - +36a37 +> MyNumberError.TooSmall => std.debug.print("<4. ", .{}), diff --git a/patches/patches/34_quiz4.patch b/patches/patches/34_quiz4.patch index 8b13789..b259352 100644 --- a/patches/patches/34_quiz4.patch +++ b/patches/patches/34_quiz4.patch @@ -1 +1,8 @@ - +12c12 +< pub fn main() void { +--- +> pub fn main() !void { +15c15 +< const my_num: u32 = getNumber(); +--- +> const my_num: u32 = try getNumber(); diff --git a/patches/patches/35_enums.patch b/patches/patches/35_enums.patch index 8b13789..ed2344b 100644 --- a/patches/patches/35_enums.patch +++ b/patches/patches/35_enums.patch @@ -1 +1,4 @@ - +23c23 +< const Ops = enum { ??? }; +--- +> const Ops = enum { dec, inc, pow }; diff --git a/patches/patches/36_enums2.patch b/patches/patches/36_enums2.patch index 8b13789..54a7094 100644 --- a/patches/patches/36_enums2.patch +++ b/patches/patches/36_enums2.patch @@ -1 +1,12 @@ - +32c32 +< blue = ???, +--- +> blue = 0x0000ff, +54c54 +< \\ Blue +--- +> \\ Blue +59c59 +< @enumToInt(???), // Oops! We're missing something! +--- +> @enumToInt(Color.blue), // Oops! We're missing something! diff --git a/patches/patches/37_structs.patch b/patches/patches/37_structs.patch index 8b13789..c26510d 100644 --- a/patches/patches/37_structs.patch +++ b/patches/patches/37_structs.patch @@ -1 +1,4 @@ - +38a39 +> health: u8, +46a48 +> .health = 100, diff --git a/patches/patches/38_structs2.patch b/patches/patches/38_structs2.patch index 8b13789..5d0d188 100644 --- a/patches/patches/38_structs2.patch +++ b/patches/patches/38_structs2.patch @@ -1 +1,7 @@ - +44a45,50 +> chars[1] = Character{ +> .class = Class.bard, +> .gold = 10, +> .health = 100, +> .experience = 20, +> }; diff --git a/patches/patches/39_pointers.patch b/patches/patches/39_pointers.patch index 8b13789..57d67e5 100644 --- a/patches/patches/39_pointers.patch +++ b/patches/patches/39_pointers.patch @@ -1 +1,4 @@ - +33c33 +< num2 = ???; +--- +> num2 = num1_pointer.*; diff --git a/patches/patches/40_pointers2.patch b/patches/patches/40_pointers2.patch index 8b13789..a69cb20 100644 --- a/patches/patches/40_pointers2.patch +++ b/patches/patches/40_pointers2.patch @@ -1 +1,4 @@ - +24c24 +< const b: *u8 = &a; // fix this! +--- +> const b: *const u8 = &a; // fix this! diff --git a/patches/patches/41_pointers3.patch b/patches/patches/41_pointers3.patch index 8b13789..02f7744 100644 --- a/patches/patches/41_pointers3.patch +++ b/patches/patches/41_pointers3.patch @@ -1 +1,4 @@ - +34c34 +< ??? p: ??? = undefined; +--- +> var p: *u8 = undefined; diff --git a/patches/patches/42_pointers4.patch b/patches/patches/42_pointers4.patch index 8b13789..29ca2d0 100644 --- a/patches/patches/42_pointers4.patch +++ b/patches/patches/42_pointers4.patch @@ -1 +1,4 @@ - +31c31 +< ??? = 5; // fix me! +--- +> x.* = 5; // fix me! diff --git a/patches/patches/43_pointers5.patch b/patches/patches/43_pointers5.patch index 8b13789..8a73551 100644 --- a/patches/patches/43_pointers5.patch +++ b/patches/patches/43_pointers5.patch @@ -1 +1,4 @@ - +60c60 +< printCharacter(???); +--- +> printCharacter(&glorp); diff --git a/patches/patches/44_quiz5.patch b/patches/patches/44_quiz5.patch index 8b13789..44d4451 100644 --- a/patches/patches/44_quiz5.patch +++ b/patches/patches/44_quiz5.patch @@ -1 +1,4 @@ - +21a22 +> var elephantB = Elephant{ .letter = 'B' }; +27a29 +> elephantB.tail = &elephantC; diff --git a/patches/patches/45_optionals.patch b/patches/patches/45_optionals.patch index 8b13789..c945b5a 100644 --- a/patches/patches/45_optionals.patch +++ b/patches/patches/45_optionals.patch @@ -1 +1,4 @@ - +32c32 +< var answer: u8 = result; +--- +> var answer: u8 = result orelse 42; -- cgit v1.2.3-ZIG