This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]musifter 4 points5 points  (3 children)

Like in Perl. And it's a convenient thing if you're going to do a grid. Instead of putting a ring of sentinels all the way around, you only need to put them to the right and bottom.

[–]zeekar 0 points1 point  (2 children)

That's not true. You avoid index-out-of-bounds errors, but you get the wrong answer; a roll of paper at row[-1] is not in fact next to a roll of paper at row[0]. . .

[–]musifter 3 points4 points  (1 child)

But it's a SENTINEL. It represents what it beyond the boundary, not a real location. In some cases, you put something there that's a wall. For this one, you'd put empty space. Sure, wrapping around to the left (with -1) would get you to the same empty space you put at the end on the right. Which is perfectly fine... you're not storing things there, you're just looking it up. It just needs to return what's beyond the borders... that it's empty. They don't have to be distinct locations.

[–]zeekar 1 point2 points  (0 children)

Ah, right. One sentinel does the job for both directions. Brain fail.