diff options
| author | Chris Boesch <[email protected]> | 2023-11-21 15:01:22 +0100 |
|---|---|---|
| committer | Chris Boesch <[email protected]> | 2023-11-21 15:01:22 +0100 |
| commit | 7679f93f688452b2236d20b49f92569b8d56e20d (patch) | |
| tree | 26712b6e6bd28c5a265d9831246e1226f6944c4f /exercises | |
| parent | b7015c2d9d50da77cf1a3897f84e1b736649beef (diff) | |
| download | ziglings-7679f93f688452b2236d20b49f92569b8d56e20d.tar.xz ziglings-7679f93f688452b2236d20b49f92569b8d56e20d.zip | |
Converted var to const if there is no mutation in var.
This is checked from compiler version 0.12.0-dev.1664
Diffstat (limited to 'exercises')
| -rw-r--r-- | exercises/025_errors5.zig | 2 | ||||
| -rw-r--r-- | exercises/029_errdefer.zig | 4 | ||||
| -rw-r--r-- | exercises/039_pointers.zig | 2 | ||||
| -rw-r--r-- | exercises/048_methods2.zig | 2 | ||||
| -rw-r--r-- | exercises/049_quiz6.zig | 2 | ||||
| -rw-r--r-- | exercises/055_unions.zig | 4 | ||||
| -rw-r--r-- | exercises/056_unions2.zig | 4 | ||||
| -rw-r--r-- | exercises/057_unions3.zig | 4 | ||||
| -rw-r--r-- | exercises/058_quiz7.zig | 4 | ||||
| -rw-r--r-- | exercises/067_comptime2.zig | 8 | ||||
| -rw-r--r-- | exercises/070_comptime5.zig | 6 | ||||
| -rw-r--r-- | exercises/072_comptime7.zig | 2 | ||||
| -rw-r--r-- | exercises/075_quiz8.zig | 4 | ||||
| -rw-r--r-- | exercises/076_sentinels.zig | 2 | ||||
| -rw-r--r-- | exercises/080_anonymous_structs.zig | 4 | ||||
| -rw-r--r-- | exercises/092_interfaces.zig | 2 | ||||
| -rw-r--r-- | exercises/096_memory_allocation.zig | 4 |
17 files changed, 30 insertions, 30 deletions
diff --git a/exercises/025_errors5.zig b/exercises/025_errors5.zig index 63595b1..94bf1c7 100644 --- a/exercises/025_errors5.zig +++ b/exercises/025_errors5.zig @@ -26,7 +26,7 @@ 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". // - var x = detect(n); + const x = detect(n); return x + 5; } diff --git a/exercises/029_errdefer.zig b/exercises/029_errdefer.zig index 82fdfe1..39ab306 100644 --- a/exercises/029_errdefer.zig +++ b/exercises/029_errdefer.zig @@ -21,8 +21,8 @@ const MyErr = error{ GetFail, IncFail }; pub fn main() void { // We simply quit the entire program if we fail to get a number: - var a: u32 = makeNumber() catch return; - var b: u32 = makeNumber() catch return; + const a: u32 = makeNumber() catch return; + const b: u32 = makeNumber() catch return; std.debug.print("Numbers: {}, {}\n", .{ a, b }); } diff --git a/exercises/039_pointers.zig b/exercises/039_pointers.zig index d545525..24ca46d 100644 --- a/exercises/039_pointers.zig +++ b/exercises/039_pointers.zig @@ -24,7 +24,7 @@ const std = @import("std"); pub fn main() void { var num1: u8 = 5; - var num1_pointer: *u8 = &num1; + const num1_pointer: *u8 = &num1; var num2: u8 = undefined; diff --git a/exercises/048_methods2.zig b/exercises/048_methods2.zig index 3291965..a1fbe9e 100644 --- a/exercises/048_methods2.zig +++ b/exercises/048_methods2.zig @@ -24,7 +24,7 @@ const Elephant = struct { pub fn print(self: *Elephant) void { // Prints elephant letter and [v]isited - var v: u8 = if (self.visited) 'v' else ' '; + const v: u8 = if (self.visited) 'v' else ' '; std.debug.print("{u}{u} ", .{ self.letter, v }); } }; diff --git a/exercises/049_quiz6.zig b/exercises/049_quiz6.zig index 92541a5..9dbea51 100644 --- a/exercises/049_quiz6.zig +++ b/exercises/049_quiz6.zig @@ -37,7 +37,7 @@ const Elephant = struct { pub fn print(self: *Elephant) void { // Prints elephant letter and [v]isited - var v: u8 = if (self.visited) 'v' else ' '; + const v: u8 = if (self.visited) 'v' else ' '; std.debug.print("{u}{u} ", .{ self.letter, v }); } }; diff --git a/exercises/055_unions.zig b/exercises/055_unions.zig index 6339fc8..794f2df 100644 --- a/exercises/055_unions.zig +++ b/exercises/055_unions.zig @@ -53,8 +53,8 @@ const AntOrBee = enum { a, b }; pub fn main() void { // We'll just make one bee and one ant to test them out: - var ant = Insect{ .still_alive = true }; - var bee = Insect{ .flowers_visited = 15 }; + const ant = Insect{ .still_alive = true }; + const bee = Insect{ .flowers_visited = 15 }; std.debug.print("Insect report! ", .{}); diff --git a/exercises/056_unions2.zig b/exercises/056_unions2.zig index e4294db..c46d133 100644 --- a/exercises/056_unions2.zig +++ b/exercises/056_unions2.zig @@ -38,8 +38,8 @@ const Insect = union(InsectStat) { }; pub fn main() void { - var ant = Insect{ .still_alive = true }; - var bee = Insect{ .flowers_visited = 16 }; + const ant = Insect{ .still_alive = true }; + const bee = Insect{ .flowers_visited = 16 }; std.debug.print("Insect report! ", .{}); diff --git a/exercises/057_unions3.zig b/exercises/057_unions3.zig index 142180f..a5017d2 100644 --- a/exercises/057_unions3.zig +++ b/exercises/057_unions3.zig @@ -21,8 +21,8 @@ const Insect = union(InsectStat) { }; pub fn main() void { - var ant = Insect{ .still_alive = true }; - var bee = Insect{ .flowers_visited = 17 }; + const ant = Insect{ .still_alive = true }; + const bee = Insect{ .flowers_visited = 17 }; std.debug.print("Insect report! ", .{}); diff --git a/exercises/058_quiz7.zig b/exercises/058_quiz7.zig index bbdebf6..cf32fc3 100644 --- a/exercises/058_quiz7.zig +++ b/exercises/058_quiz7.zig @@ -273,7 +273,7 @@ const HermitsNotebook = struct { // distance) than the one we'd noted before. If it is, we // overwrite the old entry with the new one. fn checkNote(self: *HermitsNotebook, note: NotebookEntry) void { - var existing_entry = self.getEntry(note.place); + const existing_entry = self.getEntry(note.place); if (existing_entry == null) { self.entries[self.end_of_entries] = note; @@ -386,7 +386,7 @@ pub fn main() void { // "start" entry we just added) until we run out, at which point // we'll have checked every reachable Place. while (notebook.hasNextEntry()) { - var place_entry = notebook.getNextEntry(); + const place_entry = notebook.getNextEntry(); // For every Path that leads FROM the current Place, create a // new note (in the form of a NotebookEntry) with the diff --git a/exercises/067_comptime2.zig b/exercises/067_comptime2.zig index 7d4bdb0..6b9b14a 100644 --- a/exercises/067_comptime2.zig +++ b/exercises/067_comptime2.zig @@ -38,16 +38,16 @@ pub fn main() void { var count = 0; count += 1; - var a1: [count]u8 = .{'A'} ** count; + const a1: [count]u8 = .{'A'} ** count; count += 1; - var a2: [count]u8 = .{'B'} ** count; + const a2: [count]u8 = .{'B'} ** count; count += 1; - var a3: [count]u8 = .{'C'} ** count; + const a3: [count]u8 = .{'C'} ** count; count += 1; - var a4: [count]u8 = .{'D'} ** count; + const a4: [count]u8 = .{'D'} ** count; print("{s} {s} {s} {s}\n", .{ a1, a2, a3, a4 }); diff --git a/exercises/070_comptime5.zig b/exercises/070_comptime5.zig index 3b85aae..afd4ae8 100644 --- a/exercises/070_comptime5.zig +++ b/exercises/070_comptime5.zig @@ -83,19 +83,19 @@ const DuctError = error{UnmatchedDiameters}; pub fn main() void { // This is a real duck! - var ducky1 = Duck{ + const ducky1 = Duck{ .eggs = 0, .loudness = 3, }; // This is not a real duck, but it has quack() and waddle() // abilities, so it's still a "duck". - var ducky2 = RubberDuck{ + const ducky2 = RubberDuck{ .in_bath = false, }; // This is not even remotely a duck. - var ducky3 = Duct{ + const ducky3 = Duct{ .diameter = 17, .length = 165, .galvanized = true, diff --git a/exercises/072_comptime7.zig b/exercises/072_comptime7.zig index 9bc30fb..631e75b 100644 --- a/exercises/072_comptime7.zig +++ b/exercises/072_comptime7.zig @@ -39,7 +39,7 @@ pub fn main() void { // This gets the digit from the "instruction". Can you // figure out why we subtract '0' from it? - comptime var digit = instructions[i + 1] - '0'; + const digit = instructions[i + 1] - '0'; // This 'switch' statement contains the actual work done // at runtime. At first, this doesn't seem exciting... diff --git a/exercises/075_quiz8.zig b/exercises/075_quiz8.zig index 12b460c..63d208b 100644 --- a/exercises/075_quiz8.zig +++ b/exercises/075_quiz8.zig @@ -110,7 +110,7 @@ const HermitsNotebook = struct { } fn checkNote(self: *HermitsNotebook, note: NotebookEntry) void { - var existing_entry = self.getEntry(note.place); + const existing_entry = self.getEntry(note.place); if (existing_entry == null) { self.entries[self.end_of_entries] = note; @@ -180,7 +180,7 @@ pub fn main() void { notebook.checkNote(working_note); while (notebook.hasNextEntry()) { - var place_entry = notebook.getNextEntry(); + const place_entry = notebook.getNextEntry(); for (place_entry.place.paths) |*path| { working_note = NotebookEntry{ diff --git a/exercises/076_sentinels.zig b/exercises/076_sentinels.zig index 1af59da..4b1afb1 100644 --- a/exercises/076_sentinels.zig +++ b/exercises/076_sentinels.zig @@ -46,7 +46,7 @@ pub fn main() void { var nums = [_:0]u32{ 1, 2, 3, 4, 5, 6 }; // And here's a zero-terminated many-item pointer: - var ptr: [*:0]u32 = &nums; + const ptr: [*:0]u32 = &nums; // For fun, let's replace the value at position 3 with the // sentinel value 0. This seems kind of naughty. diff --git a/exercises/080_anonymous_structs.zig b/exercises/080_anonymous_structs.zig index 8205641..55dedd4 100644 --- a/exercises/080_anonymous_structs.zig +++ b/exercises/080_anonymous_structs.zig @@ -48,13 +48,13 @@ pub fn main() void { // * circle1 should hold i32 integers // * circle2 should hold f32 floats // - var circle1 = ??? { + const circle1 = ??? { .center_x = 25, .center_y = 70, .radius = 15, }; - var circle2 = ??? { + const circle2 = ??? { .center_x = 25.234, .center_y = 70.999, .radius = 15.714, diff --git a/exercises/092_interfaces.zig b/exercises/092_interfaces.zig index 7c958eb..7775dd5 100644 --- a/exercises/092_interfaces.zig +++ b/exercises/092_interfaces.zig @@ -96,7 +96,7 @@ const Insect = union(enum) { }; pub fn main() !void { - var my_insects = [_]Insect{ + const my_insects = [_]Insect{ Insect{ .ant = Ant{ .still_alive = true } }, Insect{ .bee = Bee{ .flowers_visited = 17 } }, Insect{ .grasshopper = Grasshopper{ .distance_hopped = 32 } }, diff --git a/exercises/096_memory_allocation.zig b/exercises/096_memory_allocation.zig index 6e818b5..1ece922 100644 --- a/exercises/096_memory_allocation.zig +++ b/exercises/096_memory_allocation.zig @@ -52,7 +52,7 @@ fn runningAverage(arr: []const f64, avg: []f64) void { pub fn main() !void { // pretend this was defined by reading in user input - var arr: []const f64 = &[_]f64{ 0.3, 0.2, 0.1, 0.1, 0.4 }; + const arr: []const f64 = &[_]f64{ 0.3, 0.2, 0.1, 0.1, 0.4 }; // initialize the allocator var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); @@ -64,7 +64,7 @@ pub fn main() !void { const allocator = arena.allocator(); // allocate memory for this array - var avg: []f64 = ???; + const avg: []f64 = ???; runningAverage(arr, avg); std.debug.print("Running Average: ", .{}); |
