move turnleft pickbeeper putbeeper turnoff
Each Guido van Robot instruction must be on a separate line. A sequence of
one or more Guido van Robot instructions that are all indented the same
number of spaces compose a block of code.
<instruction>
refers to any of the five primitive
instructions above, the conditional branching or iteration instructions below,
or a user defined instruction.
<instruction> <instruction> ... <instruction>
Conditional branching refers to the ability of a program to
alter it's flow of execution based on the result of the
evaluation of a conditional. The three types of conditional
branching instructions in Guido van Robot are if
and
if/else
and if/elif/else
.
<test>
refers to one of the eighteen conditionals below.
if <test>: <block>
if <test>: <block> else: <block>
if <test>: <block> elif <test>: <block> ... elif <test>: <block> else: <block>
GvR has eighteen built-in tests that are divided into three groups: the first six are wall tests, the next four are beeper tests, and the last eight are compass tests:
front_is_clear front_is_blocked left_is_clear left_is_blocked right_is_clear right_is_blocked next_to_a_beeper not_next_to_a_beeper any_beepers_in_beeper_bag no_beepers_in_beeper_bag facing_north not_facing_north facing_south not_facing_south facing_east not_facing_east facing_west not_facing_west
Iteration refers to the ability of a program to repeate an
instruction (or block of instructions) over and over until some condition is
met. The two types of iteration instructions are the do
and
while
instructions.
<positive_number>
must be an integer greater than 0.
do <positive_number>: <block>
while <test>: <block>
New instructions can be created for Guido van Robot using the
define
statement. <new_name>
can
be any sequence of letters or digits as long as it begins with a letter and is
not already used as an instruction. Letters for Guido van
Robot are A..Z, a..z, and the underscore (_) character. Guido van Robot is
case sensitive, so TurnRight, turnright, and turnRight are all different names.
define <new_name>: <block>
Execution of a GvR program ends with the turnoff
instruction.
Any program which reaches the end of its instruction sequence without
encountering turnoff
is considered in error. Thus the simplest
GvR program is:
turnoff
Given the following world:
The following program will make Guido follow the right wall until he encouters a beeper:
define turnright: do 3: turnleft define follow_right_wall: if right_is_clear: turnright move elif front_is_clear: move else: turnleft while not_next_to_a_beeper: follow_right_wall turnoff
Copyright © 2004 Jeffrey Elkner