diff options
author | Dave Gauer <dave@ratfactor.com> | 2021-04-14 11:00:25 -0400 |
---|---|---|
committer | Dave Gauer <dave@ratfactor.com> | 2021-04-14 11:00:25 -0400 |
commit | 6f3ab8b0251fb07d8665ca98dca6510298c76bd2 (patch) | |
tree | 8e7de610941da50b20433b356ff242008516a536 | |
parent | e780328b253dfd948ca84535767c98dd2adf383e (diff) | |
download | ziglings-6f3ab8b0251fb07d8665ca98dca6510298c76bd2.tar.gz ziglings-6f3ab8b0251fb07d8665ca98dca6510298c76bd2.tar.bz2 ziglings-6f3ab8b0251fb07d8665ca98dca6510298c76bd2.tar.xz ziglings-6f3ab8b0251fb07d8665ca98dca6510298c76bd2.zip |
Added type reflection to 066
-rw-r--r-- | build.zig | 2 | ||||
-rw-r--r-- | exercises/066_comptime.zig | 14 |
2 files changed, 13 insertions, 3 deletions
@@ -333,7 +333,7 @@ const exercises = [_]Exercise{ }, .{ .main_file = "066_comptime.zig", - .output = "const_int=12345, const_float=987.654, var_int=54321, var_float=456.789", + .output = "Immutable: 12345, 987.654; Mutable: 54321, 456.789; Types: comptime_int, comptime_float, u32, f32", .hint = "It may help to read this one out loud to your favorite stuffed animal until it sinks in completely." }, }; diff --git a/exercises/066_comptime.zig b/exercises/066_comptime.zig index 20a96a7..879ae48 100644 --- a/exercises/066_comptime.zig +++ b/exercises/066_comptime.zig @@ -47,7 +47,7 @@ pub fn main() void { const const_int = 12345; const const_float = 987.654; - print("const_int={}, const_float={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". @@ -70,5 +70,15 @@ pub fn main() void { var_int = 54321; var_float = 456.789; - print("var_int={}, var_float={d:.3}\n", .{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 + // needed! + print("Types: {}, {}, {}, {}\n", .{ + @TypeOf(const_int), + @TypeOf(const_float), + @TypeOf(var_int), + @TypeOf(var_float), + }); } |