ziglings icon indicating copy to clipboard operation
ziglings copied to clipboard

Ex 046 confusing (optional 'tail' syntax comes from previous exercise)

Open ratfactor opened this issue 2 years ago • 1 comments

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.

ratfactor avatar Jan 05 '23 22:01 ratfactor

thank you. i was stuck at this too

treeshateorcs avatar Jun 04 '23 04:06 treeshateorcs