Extending Karel's Vocabulary
How can we invent new instructions for Karel?
We can invent a new instruction for Karel with the
DEFINE-NEW-INSTRUCTION
command. The definition below introduces
the instruction named forward
:
DEFINE-NEW-INSTRUCTION forward AS move END
Thge instructions between AS
and END
define the
sequence of things the new instruction is to do.
Where do definitions go in a program?
Definitions of new instructions are placed between the
BEGINNING-OF-PROGRAM
and the
BEGINNING-OF-EXECUTION
in a program. Here is a complete
program using the new instruction named forward:
BEGINNING-OF-PROGRAM
DEFINE-NEW-INSTRUCTION forward AS
move
END
BEGINNING-OF-EXECUTION
forward
turnoff
END-OF-EXECUTION
END-OF-PROGRAM
This document is copyright 1994 by Joseph N. Wilson.
$Id$