diff --git a/exercises/010_if2.zig b/exercises/010_if2.zig index d0c8cac..f0ffb43 100644 --- a/exercises/010_if2.zig +++ b/exercises/010_if2.zig @@ -1,16 +1,16 @@ // // If statements are also valid expressions: // -// var foo: u8 = if (a) 2 else 3; +// const foo: u8 = if (a) 2 else 3; // const std = @import("std"); pub fn main() void { - var discount = true; + const discount = true; // Please use an if...else expression to set "price". // If discount is true, the price should be $17, otherwise $20: - var price: u8 = if ???; + const price: u8 = if ???; std.debug.print("With the discount, the price is ${}.\n", .{price}); } diff --git a/exercises/016_for2.zig b/exercises/016_for2.zig index 6fbdb2a..0eda182 100644 --- a/exercises/016_for2.zig +++ b/exercises/016_for2.zig @@ -29,7 +29,7 @@ pub fn main() void { // Note that we convert the usize i to a u32 with // @intCast(), a builtin function just like @import(). // We'll learn about these properly in a later exercise. - var place_value = std.math.pow(u32, 2, @intCast(u32, i)); + const place_value = std.math.pow(u32, 2, @intCast(u32, i)); value += place_value * bit; } diff --git a/exercises/017_quiz2.zig b/exercises/017_quiz2.zig index a61e38b..6f32c2e 100644 --- a/exercises/017_quiz2.zig +++ b/exercises/017_quiz2.zig @@ -13,7 +13,7 @@ const std = import standard library; function main() void { var i: u8 = 1; - var stop_at: u8 = 16; + const stop_at: u8 = 16; // What kind of loop is this? A 'for' or a 'while'? ??? (i <= stop_at) : (i += 1) { diff --git a/exercises/023_errors3.zig b/exercises/023_errors3.zig index 81dd733..195f21a 100644 --- a/exercises/023_errors3.zig +++ b/exercises/023_errors3.zig @@ -11,8 +11,8 @@ const std = @import("std"); const MyNumberError = error{TooSmall}; pub fn main() void { - var a: u32 = addTwenty(44) catch 22; - var b: u32 = addTwenty(4) ??? 22; + const a: u32 = addTwenty(44) catch 22; + const b: u32 = addTwenty(4) ??? 22; std.debug.print("a={}, b={}\n", .{ a, b }); } diff --git a/exercises/024_errors4.zig b/exercises/024_errors4.zig index c2f4f6f..02ec0f2 100644 --- a/exercises/024_errors4.zig +++ b/exercises/024_errors4.zig @@ -21,9 +21,9 @@ const MyNumberError = error{ pub fn main() void { // The "catch 0" below is a temporary hack to deal with // makeJustRight()'s returned 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; + const a: u32 = makeJustRight(44) catch 0; + const b: u32 = makeJustRight(14) catch 0; + const c: u32 = makeJustRight(4) catch 0; std.debug.print("a={}, b={}, c={}\n", .{ a, b, c }); } diff --git a/exercises/025_errors5.zig b/exercises/025_errors5.zig index 8739e4a..63595b1 100644 --- a/exercises/025_errors5.zig +++ b/exercises/025_errors5.zig @@ -15,9 +15,9 @@ 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; + const a: u32 = addFive(44) catch 0; + const b: u32 = addFive(14) catch 0; + const c: u32 = addFive(4) catch 0; std.debug.print("a={}, b={}, c={}\n", .{ a, b, c }); } diff --git a/exercises/031_switch2.zig b/exercises/031_switch2.zig index d8af6e6..cf5b5a5 100644 --- a/exercises/031_switch2.zig +++ b/exercises/031_switch2.zig @@ -2,7 +2,7 @@ // What's really nice is that you can use a switch statement as an // expression to return a value. // -// var a = switch (x) { +// const a = switch (x) { // 1 => 9, // 2 => 16, // 3 => 7, diff --git a/exercises/036_enums2.zig b/exercises/036_enums2.zig index 820a71e..11af153 100644 --- a/exercises/036_enums2.zig +++ b/exercises/036_enums2.zig @@ -9,7 +9,7 @@ // @enumToInt(). We'll learn about builtins properly in a later // exercise. // -// var my_stuff: u8 = @enumToInt(Stuff.foo); +// const my_stuff: u8 = @enumToInt(Stuff.foo); // // Note how that built-in function starts with "@" just like the // @import() function we've been using. diff --git a/exercises/045_optionals.zig b/exercises/045_optionals.zig index 1327e4c..494c960 100644 --- a/exercises/045_optionals.zig +++ b/exercises/045_optionals.zig @@ -29,7 +29,7 @@ pub fn main() void { // Please threaten the result so that answer is either the // integer value from deepThought() OR the number 42: - var answer: u8 = result; + const answer: u8 = result; std.debug.print("The Ultimate Answer: {}.\n", .{answer}); } diff --git a/exercises/047_methods.zig b/exercises/047_methods.zig index 6b2dbef..d2e3ee6 100644 --- a/exercises/047_methods.zig +++ b/exercises/047_methods.zig @@ -78,7 +78,7 @@ pub fn main() void { }; var aliens_alive = aliens.len; - var heat_ray = HeatRay{ .damage = 7 }; // We've been given a heat ray weapon. + const heat_ray = HeatRay{ .damage = 7 }; // We've been given a heat ray weapon. // We'll keep checking to see if we've killed all the aliens yet. while (aliens_alive > 0) { diff --git a/exercises/059_integers.zig b/exercises/059_integers.zig index a497efa..4410079 100644 --- a/exercises/059_integers.zig +++ b/exercises/059_integers.zig @@ -18,7 +18,7 @@ const print = @import("std").debug.print; pub fn main() void { - var zig = [_]u8{ + const zig = [_]u8{ 0o131, // octal 0b1101000, // binary 0x66, // hex diff --git a/exercises/060_floats.zig b/exercises/060_floats.zig index 1320171..69b3946 100644 --- a/exercises/060_floats.zig +++ b/exercises/060_floats.zig @@ -43,7 +43,7 @@ pub fn main() void { // // We'll convert this weight from tons to kilograms at a // conversion of 907.18kg to the ton. - var shuttle_weight: f16 = 907.18 * 2200; + const shuttle_weight: f16 = 907.18 * 2200; // By default, float values are formatted in scientific // notation. Try experimenting with '{d}' and '{d:.3}' to see diff --git a/patches/patches/010_if2.patch b/patches/patches/010_if2.patch index e78f644..3ce48c2 100644 --- a/patches/patches/010_if2.patch +++ b/patches/patches/010_if2.patch @@ -1,4 +1,4 @@ 13c13 -< var price: u8 = if ???; +< const price: u8 = if ???; --- -> var price: u8 = if (discount) 17 else 20; +> const price: u8 = if (discount) 17 else 20; diff --git a/patches/patches/023_errors3.patch b/patches/patches/023_errors3.patch index a850116..9068e4a 100644 --- a/patches/patches/023_errors3.patch +++ b/patches/patches/023_errors3.patch @@ -1,7 +1,7 @@ 15c15 -< var b: u32 = addTwenty(4) ??? 22; +< const b: u32 = addTwenty(4) ??? 22; --- -> var b: u32 = addTwenty(4) catch 22; +> const b: u32 = addTwenty(4) catch 22; 22c22 < fn addTwenty(n: u32) ??? { --- diff --git a/patches/patches/045_optionals.patch b/patches/patches/045_optionals.patch index c945b5a..f1b9ddd 100644 --- a/patches/patches/045_optionals.patch +++ b/patches/patches/045_optionals.patch @@ -1,4 +1,4 @@ 32c32 -< var answer: u8 = result; +< const answer: u8 = result; --- -> var answer: u8 = result orelse 42; +> const answer: u8 = result orelse 42; diff --git a/patches/patches/060_floats.patch b/patches/patches/060_floats.patch index d20986e..38ebb41 100644 --- a/patches/patches/060_floats.patch +++ b/patches/patches/060_floats.patch @@ -1,4 +1,4 @@ 43c43 -< var shuttle_weight: f16 = 907.18 * 2200; +< const shuttle_weight: f16 = 907.18 * 2200; --- -> var shuttle_weight: f32 = 907.18 * 2200.0; +> const shuttle_weight: f32 = 907.18 * 2200.0;