Work has kept me from writing about this until now. In late January, I volunteered to run a “Computer Programmers” cluster for thirteen grade seven and eight students at a local early and middle years school. We would meet for an hour six times over five weeks.
On the first day, to keep the focus on programming rather than computers (and to break the ice), we played a game inspired by NASA’s Curiosity rover. After watching short video about rover driver Vandi Verma, students paired up and took turns playing the roles of programmer and rover. The goal, initially, was to program a rover to circumnavigate the rectangular room. Then, programmers tested their rovers on different levels of the terraced octagonal pit in the middle of the room.
A programmer wrote the program on a sheet of paper in the rover language. When handed the paper, the rover began to interpret the program, reading it from top to bottom, following each instruction before going on to the next. Additionally, a rover would listen for its programmer to say “REBOOT”, a powerful command that would terminate the current program and instruct the rover to return to home base.
Rover 1.0 had a very limited language:
Rover steps forward, one foot immediately in front of the other.
Rover turns left degrees.
Rover turns right degrees.
Rover stops whatever it’s doing and returns to home base.
Everyone succeeded in driving her rover around the perimeter of the room:
(STEP) (STEP) ... (STEP) (TURN-RIGHT 90) (STEP) (STEP) ... (STEP) (TURN-RIGHT 90) (STEP) (STEP) ... (STEP) (TURN-RIGHT 90) (STEP) (STEP) ... (STEP)
However, navigating the different levels of the pit required a major rewrite, and this was all the more tedious given the limited Rover 1.0 language.
We upgraded the rover language, adding three very useful operations:
A test that is true if the rover’s front foot touches an obstacle and false otherwise.
(IF test then-command else-command)
Do the test. If it’s true, do then-command. If it’s not, do else-command.
(REPEAT count commands)
Do the list of commands, in order, then do them again, a total of count times.
With these in hand, most students eliminated the individual step commands for each side of the room:
(REPEAT 40 (STEP)) (TURN-RIGHT 90) (REPEAT 35 (STEP)) (TURN-RIGHT 90) (REPEAT 40 (STEP)) (TURN-RIGHT 90) (REPEAT 35 (STEP))
Some recognised that that pit was a regular octagon and used nested loops:
(REPEAT 8 (REPEAT 16 (STEP)) (TURN-RIGHT 45))
Finally, following a little demonstration and Socratic method, a few of them discovered how to handle the room or any of the levels of the pit with a single change:
(REPEAT 40 (IF (SENSE-OBSTACLE) (TURN-RIGHT 45) (REPEAT 4 (STEP))) (REPEAT 32 (IF (SENSE-OBSTACLE) (TURN-RIGHT 45) (REPEAT 4 (STEP)))
What has any of this to do with Lisp… besides the parentheses? In this case, it’s about the parentheses: the students neither asked nor complained about them.