diff options
author | Dave Gauer <dave@ratfactor.com> | 2021-02-28 11:00:20 -0500 |
---|---|---|
committer | Dave Gauer <dave@ratfactor.com> | 2021-02-28 11:00:20 -0500 |
commit | 88a6ae6d2822e48adb73259ee0a143ea0efbb22e (patch) | |
tree | 29c575a2a9e35aa2ad6535b2fd734ffa213989de | |
parent | 7b165e88581efff98457c02d73c53e7481f2f3f0 (diff) | |
download | ziglings-88a6ae6d2822e48adb73259ee0a143ea0efbb22e.tar.gz ziglings-88a6ae6d2822e48adb73259ee0a143ea0efbb22e.tar.bz2 ziglings-88a6ae6d2822e48adb73259ee0a143ea0efbb22e.tar.xz ziglings-88a6ae6d2822e48adb73259ee0a143ea0efbb22e.zip |
Change default elephant tail to null (#25)
It was confusing to see
tail... = undefined
in the struct definition and then
if (tail == null)
later in the exercise - it appears that the mismatch would be the issue
- but that's distracting from the real issue: making the value optional!
Changing the initial value to null is still correct, but won't distract.
The only worry now is that the user will remember the undefined
definition from the previous exercise and wonder if that has to be that
way...but you can't win them all!
-rw-r--r-- | exercises/46_optionals2.zig | 2 | ||||
-rw-r--r-- | patches/patches/46_optionals2.patch | 9 |
2 files changed, 4 insertions, 7 deletions
diff --git a/exercises/46_optionals2.zig b/exercises/46_optionals2.zig index 11f37aa..ffa5867 100644 --- a/exercises/46_optionals2.zig +++ b/exercises/46_optionals2.zig @@ -9,7 +9,7 @@ const std = @import("std"); // single quotes const Elephant = struct { letter: u8, - tail: *Elephant = undefined, // <---- make this optional! + tail: *Elephant = null, // <---- make this optional! visited: bool = false, }; diff --git a/patches/patches/46_optionals2.patch b/patches/patches/46_optionals2.patch index 18284da..5becede 100644 --- a/patches/patches/46_optionals2.patch +++ b/patches/patches/46_optionals2.patch @@ -1,11 +1,8 @@ 12c12 -< tail: *Elephant = undefined, // <---- make this optional! +< tail: *Elephant = null, // <---- make this optional! --- -> tail: ?*Elephant = undefined, -39,42c39 -< // We should stop once we encounter a tail that -< // does NOT point to another element. What can -< // we put here to make that happen? +> tail: ?*Elephant = null, // <---- make this optional! +42c42 < if (e.tail == null) ???; --- > if (e.tail == null) break; |