From b12afaa577e5f9b0c3bf922ec5c1ab15893c7378 Mon Sep 17 00:00:00 2001 From: Dave Gauer Date: Sun, 28 Feb 2021 13:23:22 -0500 Subject: Added ex 48, additional comment on 46 --- exercises/46_optionals2.zig | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'exercises/46_optionals2.zig') 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, }; -- cgit v1.2.3-ZIG