Skip to content

Commit 88a6ae6

Browse files
committed
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!
1 parent 7b165e8 commit 88a6ae6

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

exercises/46_optionals2.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const std = @import("std"); // single quotes
99

1010
const Elephant = struct {
1111
letter: u8,
12-
tail: *Elephant = undefined, // <---- make this optional!
12+
tail: *Elephant = null, // <---- make this optional!
1313
visited: bool = false,
1414
};
1515

patches/patches/46_optionals2.patch

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
12c12
2-
< tail: *Elephant = undefined, // <---- make this optional!
2+
< tail: *Elephant = null, // <---- make this optional!
33
---
4-
> tail: ?*Elephant = undefined,
5-
39,42c39
6-
< // We should stop once we encounter a tail that
7-
< // does NOT point to another element. What can
8-
< // we put here to make that happen?
4+
> tail: ?*Elephant = null, // <---- make this optional!
5+
42c42
96
< if (e.tail == null) ???;
107
---
118
> if (e.tail == null) break;

0 commit comments

Comments
 (0)