diff options
Diffstat (limited to 'exercises')
| -rw-r--r-- | exercises/013_while3.zig | 4 | ||||
| -rw-r--r-- | exercises/039_pointers.zig | 2 | ||||
| -rw-r--r-- | exercises/065_builtins2.zig | 11 | ||||
| -rw-r--r-- | exercises/068_comptime3.zig | 2 | ||||
| -rw-r--r-- | exercises/082_anonymous_structs3.zig | 4 | ||||
| -rw-r--r-- | exercises/095_for3.zig | 8 | ||||
| -rw-r--r-- | exercises/103_tokenization.zig | 2 |
7 files changed, 23 insertions, 10 deletions
diff --git a/exercises/013_while3.zig b/exercises/013_while3.zig index 4cccf62..52d5ebd 100644 --- a/exercises/013_while3.zig +++ b/exercises/013_while3.zig @@ -11,8 +11,8 @@ // // } // -// The "continue expression" executes every time the loop restarts -// whether the "continue" statement happens or not. +// The "continue expression" executes every single time the loop restarts, +// even when a `continue` statement skips the rest of the loop body. // const std = @import("std"); diff --git a/exercises/039_pointers.zig b/exercises/039_pointers.zig index 24ca46d..792fcc7 100644 --- a/exercises/039_pointers.zig +++ b/exercises/039_pointers.zig @@ -4,7 +4,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 +// What is a pointer? It's a reference to a value. In this example, // bar is a reference to the memory space that currently contains the // value 5. // diff --git a/exercises/065_builtins2.zig b/exercises/065_builtins2.zig index 2d13994..4514b0b 100644 --- a/exercises/065_builtins2.zig +++ b/exercises/065_builtins2.zig @@ -137,19 +137,20 @@ pub fn main() void { } // NOTE: This exercise did not originally include the function below. -// But a change after Zig 0.10.0 added the source file name to the -// type. "Narcissus" became "065_builtins2.Narcissus". +// After Zig 0.10.0, `@typeName` began prefixing the returned type name +// with the source file name. For example, "Narcissus" became +// "065_builtins2.Narcissus". // // To fix this, we've added this function to strip the filename from // the front of the type name. (It returns a slice of the type name -// starting at the index + 1 of character ".") +// starting just after the ".") // // We'll be seeing @typeName again in Exercise 070. For now, you can // see that it takes a Type and returns a u8 "string". fn maximumNarcissism(myType: type) []const u8 { - const indexOf = @import("std").mem.indexOf; + const find = @import("std").mem.find; // Turn "065_builtins2.Narcissus" into "Narcissus" const name = @typeName(myType); - return name[indexOf(u8, name, ".").? + 1 ..]; + return name[find(u8, name, ".").? + 1 ..]; } diff --git a/exercises/068_comptime3.zig b/exercises/068_comptime3.zig index 15b8997..bb82778 100644 --- a/exercises/068_comptime3.zig +++ b/exercises/068_comptime3.zig @@ -11,7 +11,7 @@ // format string can be checked for errors at compile time rather // than crashing at runtime. // -// (The actual formatting is done by std.fmt.format() and it +// (The actual formatting is done by std.Io.Writer.print() and it // contains a complete format string parser that runs entirely at // compile time!) // diff --git a/exercises/082_anonymous_structs3.zig b/exercises/082_anonymous_structs3.zig index 469cd66..c13774f 100644 --- a/exercises/082_anonymous_structs3.zig +++ b/exercises/082_anonymous_structs3.zig @@ -118,6 +118,10 @@ fn printTuple(tuple: anytype) void { // @field(foo, "x"); // returns the value at foo.x // // The first field should print as: "0"(bool):true + // + // Hint: Be careful! If your 'lhs' is a type, @field() looks + // for declarations. If it's a value, it looks for data. + // print("\"{s}\"({any}):{any} ", .{ field.???, field.???, diff --git a/exercises/095_for3.zig b/exercises/095_for3.zig index 0d4f42f..77a1b56 100644 --- a/exercises/095_for3.zig +++ b/exercises/095_for3.zig @@ -28,6 +28,8 @@ // 0..10 is a range from 0 to 9 // 1..4 is a range from 1 to 3 // +// Crucially, the end value is EXCLUSIVE. +// // At the moment, ranges in loops are only supported in 'for' loops. // // Perhaps you recall Exercise 13? We were printing a numeric @@ -64,6 +66,12 @@ pub fn main() void { } std.debug.print("\n", .{}); + + // Let's also print every number from 1 through 15 + for (???) |n| { + std.debug.print("{} ", .{n}); + } + std.debug.print("\n", .{}); } // // That's a bit nicer, right? diff --git a/exercises/103_tokenization.zig b/exercises/103_tokenization.zig index 5c88c21..d0abb5c 100644 --- a/exercises/103_tokenization.zig +++ b/exercises/103_tokenization.zig @@ -2,7 +2,7 @@ // The functionality of the standard library is becoming increasingly // important in Zig. First of all, it is helpful to take a look at how // the individual functions are implemented. Because this is wonderfully -// suitable as a template for your own functions. In addition these +// suitable as a template for your own functions. In addition, these // standard functions are part of the basic configuration of Zig. // // This means that they are always available on every system. |
