Why does patch-here exist when turtles can access the variables and procedures of the patch they're standing on?

I got an interesting question from a student: Why does patch-here exist when turtles can access the variables and procedures of the patch they’re standing on? Or, more specifically, is there any situation that can only be implemented using patch-here, which cannot be implemented in any other way?

Hi @p276301,

It is true that most cases are probably covered by just directly accessing patch variables. However, if you want to create a patch set or otherwise keep track of specific patches for later use, you would need access to the actual agent, not just its variables. There are ways to get around this, such as patch xcor ycor, but it’s nice to have patch-here as a clearer way of expressing that.

Isaac B.

Thanks!

Thinking about it, that makes sense. I was thinking in terms of purely reflexive agents, but for agents with some kind of (possibly shared) memory or representation you may need to keep track of specific patches.

An immediate example I could think of is modelling a robotic vacuum that remembers which parts of the room it has already visited. Patches serve as the floor and can either be dirty or clean, while a turtle represents the robotic vacuum that moves around the room, cleans the floor, and remembers which patches it has already cleaned. The robot can’t simply move to the nearest dirty patch because it may not have the perception required to see that, so it has to add patches it visits to its memory.

2 Likes