ziglings
ziglings copied to clipboard
Ex 046 confusing (optional 'tail' syntax comes from previous exercise)
I got this one via email, so I'm putting it here so it's not forgotten:
The second part of the exercise
if (e.tail == null) ???;
fits the exercise's top comment explanation, but the first
tail: *Elephant = null, // Hmm... tail needs something...
part doesn't.
That's the problem with me trying to jam multiple issues into each exercise. :-/
The ?*Elephant solution comes from the PREVIOUS exercise where the top comment starts with:
// Sometimes you know that a variable might hold a value or
// it might not. Zig has a neat way of expressing this idea
// called Optionals. An optional type just has a '?' like this:
//
// var foo: ?u32 = 10;
Unless I'm mistaken, Ex. 045 demonstrates two things and tests one of them (orelse) and Ex. 046 demonstrates one thing and tests two things. I don't know what I was thinking, but it seems pretty confusing in retrospect.
thank you. i was stuck at this too