my ziglings
0

Configure Feed

Select the types of activity you want to include in your feed.

fix whitespace line-endings

Jonathan Halmen (Nov 5, 2021, 5:46 PM +0100) 29d32bfa 4c7eebbb

+26 -27
+1 -1
exercises/005_arrays2.zig
··· 33 33 // have a little preview of Zig 'for' loops instead: 34 34 // 35 35 // for (<item array>) |item| { <do something with item> } 36 - // 36 + // 37 37 // Don't worry, we'll cover looping properly in upcoming 38 38 // lessons. 39 39 //
+1 -1
exercises/059_integers.zig
··· 23 23 0b1101000, // binary 24 24 0x66, // hex 25 25 }; 26 - 26 + 27 27 print("{s} is cool.\n", .{zig}); 28 28 }
+2 -2
exercises/060_floats.zig
··· 59 59 // | exponent significand 60 60 // | 61 61 // sign 62 - // 62 + // 63 63 // This example is the decimal number 3.140625, which happens to 64 64 // be the closest representation of Pi we can make with an f16 65 65 // due to the way IEEE-754 floating points store digits: ··· 86 86 // 87 87 // Fun fact: sometimes you'll see the significand labeled as a 88 88 // "mantissa" but Donald E. Knuth says not to do that. 89 - // 89 + // 90 90 // C compatibility fact: There is also a Zig floating point type 91 91 // specifically for working with C ABIs called c_longdouble.
+1 -1
exercises/061_coercions.zig
··· 22 22 // const arr: [3]u8 = [3]u8{5, 6, 7}; 23 23 // const s: []const u8 = &arr; // to slice 24 24 // const p: [*]const u8 = &arr; // to many-item pointer 25 - // 25 + // 26 26 // 4. Single-item mutable pointers can coerce to single-item 27 27 // pointers pointing to an array of length 1. (Interesting!) 28 28 //
+2 -2
exercises/064_builtins.zig
··· 1 1 // 2 2 // The Zig compiler provides "builtin" functions. You've already 3 3 // gotten used to seeing an @import() at the top of every 4 - // Ziglings exercise. 4 + // Ziglings exercise. 5 5 // 6 6 // We've also seen @intCast() in "016_for2.zig", "058_quiz7.zig"; 7 7 // and @enumToInt() in "036_enums2.zig". ··· 51 51 // 1111 + 1 = 0000 Yes! (Real answer is 10000) 52 52 // 0000 + 1 = 0001 Yes! 53 53 // 0001 + 1 = 0010 Yes! 54 - // 54 + // 55 55 // Also, check out our fancy formatting! b:0>4 means, "print 56 56 // as a binary number, zero-pad right-aligned four digits." 57 57 print("{b:0>4} + {b:0>4} = {b:0>4} ({})", .{a, b, my_result, overflowed});
+6 -6
exercises/065_builtins2.zig
··· 1 1 // 2 2 // Zig has builtins for mathematical operations such as... 3 3 // 4 - // @sqrt @sin @cos 4 + // @sqrt @sin @cos 5 5 // @exp @log @floor 6 6 // 7 7 // ...and lots of type casting operations such as... ··· 20 20 // by exploring just THREE of Zig's MANY introspection abilities: 21 21 // 22 22 // 1. @This() type 23 - // 23 + // 24 24 // Returns the innermost struct, enum, or union that a function 25 25 // call is inside. 26 26 // 27 27 // 2. @typeInfo(comptime T: type) @import("std").builtin.TypeInfo 28 - // 28 + // 29 29 // Returns information about any type in a TypeInfo union which 30 30 // will contain different information depending on which type 31 31 // you're examining. 32 - // 32 + // 33 33 // 3. @TypeOf(...) type 34 - // 34 + // 35 35 // Returns the type common to all input parameters (each of which 36 36 // may be any expression). The type is resolved using the same 37 37 // "peer type resolution" process the compiler itself uses when ··· 46 46 me: *Narcissus = undefined, 47 47 myself: *Narcissus = undefined, 48 48 echo: void = undefined, 49 - 49 + 50 50 fn fetchTheMostBeautifulType() type { 51 51 return @This(); 52 52 }
+1 -1
exercises/066_comptime.zig
··· 27 27 // 28 28 // Zig takes these concepts further by making these optimizations 29 29 // an integral part of the language itself! 30 - // 30 + // 31 31 const print = @import("std").debug.print; 32 32 33 33 pub fn main() void {
+1 -1
exercises/067_comptime2.zig
··· 8 8 // --o-- comptime * | .. . 9 9 // * | * . . . . --*-- . * . 10 10 // . . . . . . . . . | . . . 11 - // 11 + // 12 12 // When placed before a variable declaration, 'comptime' 13 13 // guarantees that every usage of that variable will be performed 14 14 // at compile time.
+1 -1
exercises/069_comptime4.zig
··· 49 49 while (i < size) : (i += 1) { 50 50 sequence[i] = @intCast(T, i) + 1; 51 51 } 52 - 52 + 53 53 return sequence; 54 54 }
+1 -1
exercises/070_comptime5.zig
··· 140 140 // error, not a runtime panic or crash! 141 141 possible_duck.quack(); 142 142 } 143 - 143 + 144 144 return is_duck; 145 145 }
+2 -2
exercises/072_comptime7.zig
··· 49 49 '*' => value *= digit, 50 50 else => unreachable, 51 51 } 52 - // ...But it's quite a bit more exciting than it first appears. 52 + // ...But it's quite a bit more exciting than it first appears. 53 53 // The 'inline while' no longer exists at runtime and neither 54 54 // does anything else not touched directly by runtime 55 55 // code. The 'instructions' string, for example, does not ··· 61 61 // code at compile time. Guess we're compiler writers 62 62 // now. See? The wizard hat was justified after all. 63 63 } 64 - 64 + 65 65 print("{}\n", .{value}); 66 66 }
+1 -1
exercises/073_comptime8.zig
··· 56 56 } 57 57 58 58 // Fun fact: this assert() function is identical to 59 - // std.debug.assert() from the Zig Standard Library. 59 + // std.debug.assert() from the Zig Standard Library. 60 60 fn assert(ok: bool) void { 61 61 if (!ok) unreachable; 62 62 }
+1 -1
exercises/075_quiz8.zig
··· 69 69 // 70 70 // For example, we could create our own "path language" and 71 71 // create Paths from that. Something like this, perhaps: 72 - // 72 + // 73 73 // a -> (b[2]) 74 74 // b -> (a[2] d[1]) 75 75 // c -> (d[3] e[2])
+1 -1
exercises/077_sentinels2.zig
··· 22 22 // Versatility! Zig strings are compatible with C strings (which 23 23 // are null-terminated) AND can be coerced to a variety of other 24 24 // Zig types: 25 - // 25 + // 26 26 // const a: [5]u8 = "array".*; 27 27 // const b: *const [16]u8 = "pointer to array"; 28 28 // const c: []const u8 = "slice";
+1 -1
exercises/079_quoted_identifiers.zig
··· 13 13 // past the authorities: the @"" identifier quoting syntax. 14 14 // 15 15 // @"foo" 16 - // 16 + // 17 17 // Please help us safely smuggle these fugitive identifiers into 18 18 // our program: 19 19 //
+1 -1
exercises/082_anonymous_structs3.zig
··· 29 29 // If a .{} thing is what the print function wants, do we need to 30 30 // break our "tuple" apart and put it in another one? No! It's 31 31 // redundant! This will print the same thing: 32 - // 32 + // 33 33 // print("{} {}\n", foo); 34 34 // 35 35 // Aha! So now we know that print() takes a "tuple". Things are
+1 -1
exercises/084_async.zig
··· 37 37 // fn bar() void { 38 38 // fooThatSuspends(); 39 39 // } 40 - // 40 + // 41 41 // 6. The main() function cannot be async! 42 42 // 43 43 // Given facts 3 and 4, how do we fix this program (broken by facts
-1
exercises/085_async2.zig
··· 26 26 suspend {} 27 27 print("async!\n", .{}); 28 28 } 29 -
+1 -1
exercises/090_async7.zig
··· 10 10 // fn bar() void { 11 11 // fooThatMightSuspend(true); // Now bar() is async! 12 12 // } 13 - // 13 + // 14 14 // But if you KNOW the function won't suspend, you can make a 15 15 // promise to the compiler with the 'nosuspend' keyword: 16 16 //