-
Notifications
You must be signed in to change notification settings - Fork 478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem 46, is undefined == null? #25
Comments
@charlieman First off, I'm delighted that you've enjoyed Ziglings so far and I'm glad you figured out the real answer - making This But what really surprised me was that I could put
My understanding is that At the very least, I might need to add an additional comment on this exercise. Do you think adding a hint about using the In the meantime, I'm going to see if my understanding of the Thanks! |
Ha ha. Just our luck, I think In the meantime, I think my understanding wasn't entirely wrong, so let me know what you think about adding the hint. |
Neat, I'm thrilled my question led to a bug in the compiler itself. I don't think the extra hint is necessary, but maybe the exercise could use If I try to print
It prints |
Wait, I take that last part back. With this little example it prints
However if I uncomment |
as you seem to have discovered judging by your next comment, the value of In safe build modes (debug and release safe) zig uses |
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!
After hemming and hawing over this for a while, I agree that changing the default value in the definition to |
Thanks @ifreund ! This exercise and some additional semantic issues that have arisen on my Zig journey recently have made it clear to me that after these struct/method exercises, we need a couple more that focus on the fundamentals of assigning and passing values (and null vs undefined). |
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!
…atfactor#25) from pr23 into main Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/25
First of all, thanks for this project, it makes learning zig so much fun!
Problem 46 asks to make
tail
optional, when I did it, I also changed the default from undefined to null (tail: ?*Elephant = null,
) thinking it needs to be null so the check on line 42 (if (e.tail == null)
) works. However I changed it back to undefined later to see if it would break and it didn't!So far it seems like
undefined == null
. I also checked with swapping the values around and what I got is:undefined != undefined
null != undefined
undefined == null
So
undefined == null
when a value is optional but not the other way around, and no two undefined are the same.Maybe there could be a note about this in the exercise, or make a new exercise that explains this?
The text was updated successfully, but these errors were encountered: