heya, so, in exercise 058 "quiz7", you're tasked to fix the following function:
// found, we return null.
fn getEntry(self: *HermitsNotebook, place: *const Place) ?*NotebookEntry {
for (&self.entries, 0..) |*entry, i| {
if (i >= self.end_of_entries) break;
// Here's where the hermit got stuck. We need to return
// an optional pointer to a NotebookEntry.
//
// What we have with "entry" is the opposite: a pointer to
// an optional NotebookEntry!
//
// To get one from the other, we need to dereference
// "entry" (with .*) and get the non-null value from the
// optional (with .?) and return the address of that. The
// if statement provides some clues about how the
// dereference and optional value "unwrapping" look
// together. Remember that you return the address with the
// "&" operator.
if (place == entry.*.?.place) return entry;
// Try to make your answer this long:__________;
}
return null;
}```
as discussed in a previous question, ".?" seems to kinda suck, but i can't think of a way to do this without it?
the issue appears to be that you need to return an optional pointer to an item in an array, but i don't understand how exactly to Un and Re wrap the value in such a way
if i try doing like, `if (entry) |nonNullEntry| { //do stuff with nonNullEntry, return it if it matches the criteria}` then i end up passing back a Const NotebookEntry, which i can only imagine is because the capture value is a new scoped const that's copied by value instead of reference or something?
either way, please do advise, i'm finding going in and messing with these functions to be useful to learn, even if i sometimes get confused like this.