A repeat statement,
is interpreted as follows:
In actuality, repeat is a macro in LOBO. Remember how macros in Scheme worked? Scheme evaluates the following program
program stack | graphic accumulator |
|
LOBO recognizes the repeat keyword, so it calls itself on a program stack which has been expanded to look like this:
program stack | graphic accumulator |
|
After the first four statements on the top of the program stack have been interpreted, i.e., ((pendown)(forward 5)(penup)(forward 5)), the program stack and graphic accumulator look like this:
program stack | graphic accumulator |
|
LOBO recognizes the repeat keyword, so it calls itself on a program stack which has been expanded to look like this:
program stack | graphic accumulator |
|
After the first four statements on the top of the program stack are interpreted, i.e., ((pendown)(forward 5)(penup)(forward 5)), the program stack and graphic accumulator look like this:
program stack | graphic accumulator |
|
LOBO recognizes the repeat keyword, so it calls itself on a program stack which has been expanded to look like this:
program stack | graphic accumulator |
|
After the first four statements on the top of the program stack are interpreted, i.e., ((pendown)(forward 5)(penup)(forward 5)), the program stack and graphic accumulator look like this:
program stack | graphic accumulator |
|
LOBO recognizes the repeat keyword, so it calls itself on a program stack which has been expanded to look like this:
program stack | graphic accumulator |
|
After the first four statements on the top of the program stack are interpreted, i.e., ((pendown)(forward 5)(penup)(forward 5)), the program stack and graphic accumulator look like this:
program stack | graphic accumulator |
|
LOBO recognizes the repeat keyword. But repeat's argument is zero, so it calls itself on the cdr of the program stack:
program stack | graphic accumulator |
() |
which is just the empty list. Consequently, LOBO is done, and it returns the value of the graphic accumulator.