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!
pull/2/head
Dave Gauer 4 years ago
parent 42e6ebd2fe
commit 077a779f3d

@ -9,7 +9,7 @@ const std = @import("std"); // single quotes
const Elephant = struct { const Elephant = struct {
letter: u8, letter: u8,
tail: *Elephant = undefined, // <---- make this optional! tail: *Elephant = null, // <---- make this optional!
visited: bool = false, visited: bool = false,
}; };

@ -1,11 +1,8 @@
12c12 12c12
< tail: *Elephant = undefined, // <---- make this optional! < tail: *Elephant = null, // <---- make this optional!
--- ---
> tail: ?*Elephant = undefined, > tail: ?*Elephant = null, // <---- make this optional!
39,42c39 42c42
< // We should stop once we encounter a tail that
< // does NOT point to another element. What can
< // we put here to make that happen?
< if (e.tail == null) ???; < if (e.tail == null) ???;
--- ---
> if (e.tail == null) break; > if (e.tail == null) break;

Loading…
Cancel
Save