aboutsummaryrefslogtreecommitdiff
path: root/exercises
diff options
context:
space:
mode:
Diffstat (limited to 'exercises')
-rw-r--r--exercises/005_arrays2.zig2
-rw-r--r--exercises/053_slices2.zig2
-rw-r--r--exercises/059_integers.zig2
-rw-r--r--exercises/060_floats.zig4
-rw-r--r--exercises/061_coercions.zig2
-rw-r--r--exercises/064_builtins.zig8
-rw-r--r--exercises/065_builtins2.zig16
-rw-r--r--exercises/066_comptime.zig8
-rw-r--r--exercises/067_comptime2.zig6
-rw-r--r--exercises/068_comptime3.zig8
-rw-r--r--exercises/069_comptime4.zig6
-rw-r--r--exercises/070_comptime5.zig2
-rw-r--r--exercises/072_comptime7.zig4
-rw-r--r--exercises/073_comptime8.zig2
-rw-r--r--exercises/075_quiz8.zig6
-rw-r--r--exercises/077_sentinels2.zig4
-rw-r--r--exercises/079_quoted_identifiers.zig2
-rw-r--r--exercises/082_anonymous_structs3.zig2
-rw-r--r--exercises/084_async.zig2
-rw-r--r--exercises/085_async2.zig1
-rw-r--r--exercises/089_async6.zig2
-rw-r--r--exercises/090_async7.zig2
22 files changed, 46 insertions, 47 deletions
diff --git a/exercises/005_arrays2.zig b/exercises/005_arrays2.zig
index acbfafc..c5df8d4 100644
--- a/exercises/005_arrays2.zig
+++ b/exercises/005_arrays2.zig
@@ -33,7 +33,7 @@ pub fn main() void {
// have a little preview of Zig 'for' loops instead:
//
// for (<item array>) |item| { <do something with item> }
- //
+ //
// Don't worry, we'll cover looping properly in upcoming
// lessons.
//
diff --git a/exercises/053_slices2.zig b/exercises/053_slices2.zig
index 18237a0..545b4da 100644
--- a/exercises/053_slices2.zig
+++ b/exercises/053_slices2.zig
@@ -31,5 +31,5 @@ pub fn main() void {
}
fn printPhrase(part1: []u8, part2: []u8, part3: []u8) void {
- std.debug.print("'{s} {s} {s}.' ", .{part1, part2, part3});
+ std.debug.print("'{s} {s} {s}.' ", .{ part1, part2, part3 });
}
diff --git a/exercises/059_integers.zig b/exercises/059_integers.zig
index e72fa2f..5a6295d 100644
--- a/exercises/059_integers.zig
+++ b/exercises/059_integers.zig
@@ -23,6 +23,6 @@ pub fn main() void {
0b1101000, // binary
0x66, // hex
};
-
+
print("{s} is cool.\n", .{zig});
}
diff --git a/exercises/060_floats.zig b/exercises/060_floats.zig
index 6ff7b50..a223257 100644
--- a/exercises/060_floats.zig
+++ b/exercises/060_floats.zig
@@ -59,7 +59,7 @@ pub fn main() void {
// | exponent significand
// |
// sign
-//
+//
// This example is the decimal number 3.140625, which happens to
// be the closest representation of Pi we can make with an f16
// due to the way IEEE-754 floating points store digits:
@@ -86,6 +86,6 @@ pub fn main() void {
//
// Fun fact: sometimes you'll see the significand labeled as a
// "mantissa" but Donald E. Knuth says not to do that.
-//
+//
// C compatibility fact: There is also a Zig floating point type
// specifically for working with C ABIs called c_longdouble.
diff --git a/exercises/061_coercions.zig b/exercises/061_coercions.zig
index e4f87d8..067edde 100644
--- a/exercises/061_coercions.zig
+++ b/exercises/061_coercions.zig
@@ -22,7 +22,7 @@
// const arr: [3]u8 = [3]u8{5, 6, 7};
// const s: []const u8 = &arr; // to slice
// const p: [*]const u8 = &arr; // to many-item pointer
-//
+//
// 4. Single-item mutable pointers can coerce to single-item
// pointers pointing to an array of length 1. (Interesting!)
//
diff --git a/exercises/064_builtins.zig b/exercises/064_builtins.zig
index 735ff9d..e1af861 100644
--- a/exercises/064_builtins.zig
+++ b/exercises/064_builtins.zig
@@ -1,7 +1,7 @@
//
// The Zig compiler provides "builtin" functions. You've already
// gotten used to seeing an @import() at the top of every
-// Ziglings exercise.
+// Ziglings exercise.
//
// We've also seen @intCast() in "016_for2.zig", "058_quiz7.zig";
// and @enumToInt() in "036_enums2.zig".
@@ -51,10 +51,10 @@ pub fn main() void {
// 1111 + 1 = 0000 Yes! (Real answer is 10000)
// 0000 + 1 = 0001 Yes!
// 0001 + 1 = 0010 Yes!
- //
+ //
// Also, check out our fancy formatting! b:0>4 means, "print
// as a binary number, zero-pad right-aligned four digits."
- print("{b:0>4} + {b:0>4} = {b:0>4} ({})", .{a, b, my_result, overflowed});
+ print("{b:0>4} + {b:0>4} = {b:0>4} ({})", .{ a, b, my_result, overflowed });
print(". Furthermore, ", .{});
@@ -70,5 +70,5 @@ pub fn main() void {
// this builtin to reverse the bits of a u8 integer.
const input: u8 = 0b11110000;
const tupni: u8 = @bitReverse(input);
- print("{b:0>8} backwards is {b:0>8}.\n", .{input, tupni});
+ print("{b:0>8} backwards is {b:0>8}.\n", .{ input, tupni });
}
diff --git a/exercises/065_builtins2.zig b/exercises/065_builtins2.zig
index ef41797..1532c2a 100644
--- a/exercises/065_builtins2.zig
+++ b/exercises/065_builtins2.zig
@@ -1,7 +1,7 @@
//
// Zig has builtins for mathematical operations such as...
//
-// @sqrt @sin @cos
+// @sqrt @sin @cos
// @exp @log @floor
//
// ...and lots of type casting operations such as...
@@ -20,18 +20,18 @@
// by exploring just THREE of Zig's MANY introspection abilities:
//
// 1. @This() type
-//
+//
// Returns the innermost struct, enum, or union that a function
// call is inside.
//
// 2. @typeInfo(comptime T: type) @import("std").builtin.TypeInfo
-//
+//
// Returns information about any type in a TypeInfo union which
// will contain different information depending on which type
// you're examining.
-//
+//
// 3. @TypeOf(...) type
-//
+//
// Returns the type common to all input parameters (each of which
// may be any expression). The type is resolved using the same
// "peer type resolution" process the compiler itself uses when
@@ -46,14 +46,14 @@ const Narcissus = struct {
me: *Narcissus = undefined,
myself: *Narcissus = undefined,
echo: void = undefined,
-
+
fn fetchTheMostBeautifulType() type {
return @This();
}
};
pub fn main() void {
- var narcissus: Narcissus = Narcissus {};
+ var narcissus: Narcissus = Narcissus{};
// Oops! We cannot leave the 'me' and 'myself' fields
// undefined. Please set them here:
@@ -70,7 +70,7 @@ pub fn main() void {
// fix this call:
const T2 = narcissus.fetchTheMostBeautifulType();
- print("A {} loves all {}es. ", .{T1, T2});
+ print("A {} loves all {}es. ", .{ T1, T2 });
// His final words as he was looking in
// those waters he habitually watched
diff --git a/exercises/066_comptime.zig b/exercises/066_comptime.zig
index 987402b..bcd0bc5 100644
--- a/exercises/066_comptime.zig
+++ b/exercises/066_comptime.zig
@@ -27,10 +27,10 @@
//
// Zig takes these concepts further by making these optimizations
// an integral part of the language itself!
-//
+//
const print = @import("std").debug.print;
-pub fn main() void {
+pub fn main() void {
// ALL numeric literals in Zig are of type comptime_int or
// comptime_float. They are of arbitrary size (as big or
// little as you need).
@@ -46,7 +46,7 @@ pub fn main() void {
const const_int = 12345;
const const_float = 987.654;
- print("Immutable: {}, {d:.3}; ", .{const_int, const_float});
+ print("Immutable: {}, {d:.3}; ", .{ const_int, const_float });
// But something changes when we assign the exact same values
// to identifiers mutably with "var".
@@ -69,7 +69,7 @@ pub fn main() void {
var_int = 54321;
var_float = 456.789;
- print("Mutable: {}, {d:.3}; ", .{var_int, var_float});
+ print("Mutable: {}, {d:.3}; ", .{ var_int, var_float });
// Bonus: Now that we're familiar with Zig's builtins, we can
// also inspect the types to see what they are, no guessing
diff --git a/exercises/067_comptime2.zig b/exercises/067_comptime2.zig
index 2d50099..7d4bdb0 100644
--- a/exercises/067_comptime2.zig
+++ b/exercises/067_comptime2.zig
@@ -8,7 +8,7 @@
// --o-- comptime * | .. .
// * | * . . . . --*-- . * .
// . . . . . . . . . | . . .
-//
+//
// When placed before a variable declaration, 'comptime'
// guarantees that every usage of that variable will be performed
// at compile time.
@@ -30,7 +30,7 @@
//
const print = @import("std").debug.print;
-pub fn main() void {
+pub fn main() void {
//
// In this contrived example, we've decided to allocate some
// arrays using a variable count! But something's missing...
@@ -49,7 +49,7 @@ pub fn main() void {
count += 1;
var a4: [count]u8 = .{'D'} ** count;
- print("{s} {s} {s} {s}\n", .{a1, a2, a3, a4});
+ print("{s} {s} {s} {s}\n", .{ a1, a2, a3, a4 });
// Builtin BONUS!
//
diff --git a/exercises/068_comptime3.zig b/exercises/068_comptime3.zig
index ebe6c8f..848d7d2 100644
--- a/exercises/068_comptime3.zig
+++ b/exercises/068_comptime3.zig
@@ -61,10 +61,10 @@ const Schooner = struct {
}
};
-pub fn main() void {
- var whale = Schooner {.name = "Whale"};
- var shark = Schooner {.name = "Shark"};
- var minnow = Schooner {.name = "Minnow"};
+pub fn main() void {
+ var whale = Schooner{ .name = "Whale" };
+ var shark = Schooner{ .name = "Shark" };
+ var minnow = Schooner{ .name = "Minnow" };
// Hey, we can't just pass this runtime variable as an
// argument to the scaleMe() method. What would let us do
diff --git a/exercises/069_comptime4.zig b/exercises/069_comptime4.zig
index c1efa46..ecec2ee 100644
--- a/exercises/069_comptime4.zig
+++ b/exercises/069_comptime4.zig
@@ -13,14 +13,14 @@
//
const print = @import("std").debug.print;
-pub fn main() void {
+pub fn main() void {
// Here we declare arrays of three different types and sizes
// at compile time from a function call. Neat!
const s1 = makeSequence(u8, 3); // creates a [3]u8
const s2 = makeSequence(u32, 5); // creates a [5]u32
const s3 = makeSequence(i64, 7); // creates a [7]i64
- print("s1={any}, s2={any}, s3={any}\n", .{s1, s2, s3});
+ print("s1={any}, s2={any}, s3={any}\n", .{ s1, s2, s3 });
}
// This function is pretty wild because it executes at runtime
@@ -49,6 +49,6 @@ fn makeSequence(comptime T: type, ??? size: usize) [???]T {
while (i < size) : (i += 1) {
sequence[i] = @intCast(T, i) + 1;
}
-
+
return sequence;
}
diff --git a/exercises/070_comptime5.zig b/exercises/070_comptime5.zig
index 714bf1c..01f4276 100644
--- a/exercises/070_comptime5.zig
+++ b/exercises/070_comptime5.zig
@@ -140,6 +140,6 @@ fn isADuck(possible_duck: anytype) bool {
// error, not a runtime panic or crash!
possible_duck.quack();
}
-
+
return is_duck;
}
diff --git a/exercises/072_comptime7.zig b/exercises/072_comptime7.zig
index 06eb92e..147b935 100644
--- a/exercises/072_comptime7.zig
+++ b/exercises/072_comptime7.zig
@@ -49,7 +49,7 @@ pub fn main() void {
'*' => value *= digit,
else => unreachable,
}
- // ...But it's quite a bit more exciting than it first appears.
+ // ...But it's quite a bit more exciting than it first appears.
// The 'inline while' no longer exists at runtime and neither
// does anything else not touched directly by runtime
// code. The 'instructions' string, for example, does not
@@ -61,6 +61,6 @@ pub fn main() void {
// code at compile time. Guess we're compiler writers
// now. See? The wizard hat was justified after all.
}
-
+
print("{}\n", .{value});
}
diff --git a/exercises/073_comptime8.zig b/exercises/073_comptime8.zig
index 6828f55..fe1f8ea 100644
--- a/exercises/073_comptime8.zig
+++ b/exercises/073_comptime8.zig
@@ -56,7 +56,7 @@ fn getLlama(i: usize) u32 {
}
// Fun fact: this assert() function is identical to
-// std.debug.assert() from the Zig Standard Library.
+// std.debug.assert() from the Zig Standard Library.
fn assert(ok: bool) void {
if (!ok) unreachable;
}
diff --git a/exercises/075_quiz8.zig b/exercises/075_quiz8.zig
index ff5e569..1e026a4 100644
--- a/exercises/075_quiz8.zig
+++ b/exercises/075_quiz8.zig
@@ -54,12 +54,12 @@ fn makePath(from: *Place, to: *Place, dist: u8) Path {
// Using our new function, these path definitions take up considerably less
// space in our program now!
-const a_paths = [_]Path{ makePath(&a, &b, 2) };
+const a_paths = [_]Path{makePath(&a, &b, 2)};
const b_paths = [_]Path{ makePath(&b, &a, 2), makePath(&b, &d, 1) };
const c_paths = [_]Path{ makePath(&c, &d, 3), makePath(&c, &e, 2) };
const d_paths = [_]Path{ makePath(&d, &b, 1), makePath(&d, &c, 3), makePath(&d, &f, 7) };
const e_paths = [_]Path{ makePath(&e, &c, 2), makePath(&e, &f, 1) };
-const f_paths = [_]Path{ makePath(&f, &d, 7) };
+const f_paths = [_]Path{makePath(&f, &d, 7)};
//
// But is it more readable? That could be argued either way.
//
@@ -69,7 +69,7 @@ const f_paths = [_]Path{ makePath(&f, &d, 7) };
//
// For example, we could create our own "path language" and
// create Paths from that. Something like this, perhaps:
-//
+//
// a -> (b[2])
// b -> (a[2] d[1])
// c -> (d[3] e[2])
diff --git a/exercises/077_sentinels2.zig b/exercises/077_sentinels2.zig
index 7a03dcd..fb8f13d 100644
--- a/exercises/077_sentinels2.zig
+++ b/exercises/077_sentinels2.zig
@@ -22,7 +22,7 @@
// Versatility! Zig strings are compatible with C strings (which
// are null-terminated) AND can be coerced to a variety of other
// Zig types:
-//
+//
// const a: [5]u8 = "array".*;
// const b: *const [16]u8 = "pointer to array";
// const c: []const u8 = "slice";
@@ -50,7 +50,7 @@ pub fn main() void {
//
// Luckily, the 'length' field makes it possible to still
// work with this value.
- const foo = WeirdContainer {
+ const foo = WeirdContainer{
.data = "Weird Data!",
.length = 11,
};
diff --git a/exercises/079_quoted_identifiers.zig b/exercises/079_quoted_identifiers.zig
index a529b60..9ef22b0 100644
--- a/exercises/079_quoted_identifiers.zig
+++ b/exercises/079_quoted_identifiers.zig
@@ -13,7 +13,7 @@
// past the authorities: the @"" identifier quoting syntax.
//
// @"foo"
-//
+//
// Please help us safely smuggle these fugitive identifiers into
// our program:
//
diff --git a/exercises/082_anonymous_structs3.zig b/exercises/082_anonymous_structs3.zig
index 6b5fe04..1214589 100644
--- a/exercises/082_anonymous_structs3.zig
+++ b/exercises/082_anonymous_structs3.zig
@@ -29,7 +29,7 @@
// If a .{} thing is what the print function wants, do we need to
// break our "tuple" apart and put it in another one? No! It's
// redundant! This will print the same thing:
-//
+//
// print("{} {}\n", foo);
//
// Aha! So now we know that print() takes a "tuple". Things are
diff --git a/exercises/084_async.zig b/exercises/084_async.zig
index abfcac8..56c9969 100644
--- a/exercises/084_async.zig
+++ b/exercises/084_async.zig
@@ -37,7 +37,7 @@
// fn bar() void {
// fooThatSuspends();
// }
-//
+//
// 6. The main() function cannot be async!
//
// Given facts 3 and 4, how do we fix this program (broken by facts
diff --git a/exercises/085_async2.zig b/exercises/085_async2.zig
index 77da106..036aefa 100644
--- a/exercises/085_async2.zig
+++ b/exercises/085_async2.zig
@@ -26,4 +26,3 @@ fn foo() void {
suspend {}
print("async!\n", .{});
}
-
diff --git a/exercises/089_async6.zig b/exercises/089_async6.zig
index 755b438..8bf50e9 100644
--- a/exercises/089_async6.zig
+++ b/exercises/089_async6.zig
@@ -44,7 +44,7 @@ pub fn main() void {
var com_title = com_frame;
var org_title = org_frame;
- print(".com: {s}, .org: {s}.\n", .{com_title, org_title});
+ print(".com: {s}, .org: {s}.\n", .{ com_title, org_title });
}
fn getPageTitle(url: []const u8) []const u8 {
diff --git a/exercises/090_async7.zig b/exercises/090_async7.zig
index 0214f34..2da3a4a 100644
--- a/exercises/090_async7.zig
+++ b/exercises/090_async7.zig
@@ -10,7 +10,7 @@
// fn bar() void {
// fooThatMightSuspend(true); // Now bar() is async!
// }
-//
+//
// But if you KNOW the function won't suspend, you can make a
// promise to the compiler with the 'nosuspend' keyword:
//