aboutsummaryrefslogtreecommitdiff
path: root/exercises/46_optionals2.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-02-28 13:23:22 -0500
committerDave Gauer <dave@ratfactor.com>2021-02-28 13:23:22 -0500
commitb12afaa577e5f9b0c3bf922ec5c1ab15893c7378 (patch)
treec8a5be6d30f4b44ea6124064fcf3e399876ab661 /exercises/46_optionals2.zig
parentfebc9dfecb5285cdaa9f4e9edb4d8331a1f1350c (diff)
downloadziglings-b12afaa577e5f9b0c3bf922ec5c1ab15893c7378.tar.gz
ziglings-b12afaa577e5f9b0c3bf922ec5c1ab15893c7378.tar.bz2
ziglings-b12afaa577e5f9b0c3bf922ec5c1ab15893c7378.tar.xz
ziglings-b12afaa577e5f9b0c3bf922ec5c1ab15893c7378.zip
Added ex 48, additional comment on 46
Diffstat (limited to 'exercises/46_optionals2.zig')
-rw-r--r--exercises/46_optionals2.zig14
1 files changed, 13 insertions, 1 deletions
diff --git a/exercises/46_optionals2.zig b/exercises/46_optionals2.zig
index a037382..d3f65bb 100644
--- a/exercises/46_optionals2.zig
+++ b/exercises/46_optionals2.zig
@@ -5,11 +5,23 @@
// linked to the first elephant. This is because we had NO CONCEPT
// of a tail that didn't point to another elephant!
//
+// We also introduce the handy ".?" shortcut:
+//
+// const foo = bar.?;
+//
+// is the same as
+//
+// const foo = bar orelse unreachable;
+//
+// See if you can find where we use this shortcut below.
+//
+// Now let's make those elephant tails optional!
+//
const std = @import("std");
const Elephant = struct {
letter: u8,
- tail: *Elephant = null, // <---- make this optional!
+ tail: *Elephant = null, // Hmm... tail needs something...
visited: bool = false,
};