To start answering these questions, have a look at the code in figure 3, below:
resolve [p,s,r]. stm . holding(+) => exec([use]). over(+) => exec([grab]). can_see(+) => move_towards(+).
Figure The source of psbug1.
If you know how to use the editor, you can display this code on your
screen via the Ved
showlib command. This is described near the
end of my editor handout. If you want to try, give the Ved command
showlib psbug1either from Prolog, or as a Ved ENTER command.
What is going on in the above code? It's in three parts. The first,
resolve [p,s,r], specifies the resolution strategies to be used.
These letters stand for priority, specificity and recency respectively,
and the methods are applied in this order. Priority is irrelevant here.
It's possible, when writing rules, to give some of them higher priority
than others. But I haven't done this. Specificity refers to the
complexity of conditions. This doesn't matter here either, since all the
conditions are equally complex.
So the resolve stage first looks for the rules with the highest
priority. Since they all have the same priority, this doesn't help. It
then looks for the rule with the most specific - most complex -
condition. This doesn't help either. Finally it sorts the rules by
recency, choosing the least recently fired. You will see this process
reflected in the view diagnostics, and if you know how to use the
v control command, you can move around the view window and
inspect it in more detail.
The second part of the code,
stm , specifies the initial
contents of short-term memory. The brackets with nothing between them
mean that it's empty. It's actually going to stay empty throughout the
life, since this bug reacts directly to its perceptions, and doesn't
build up any memory structures. This is why the view window repeatedly
displays the line
1 PS STM ismeaning there's nothing in STM.
The third part is the most important - the rules. Each rule is separated into two parts, a condition and an action. Before explaining these further, it's necessary to explain a bit about the bug's sense of ``vision''.