► |  | Teachpacks

1 | Ht DP Teachpacks
2 | Ht DP/ 2e Teachpacks

▼ | 1 | Ht DP Teachpacks

1.1 | Manipulating Images: "image.ss"
1.2 | Simulations and Animations: "world.ss"
1.3 | Converting Temperatures: "convert.ss"
1.4 | Guessing Numbers: "guess.ss"
1.5 | Master Minding: "master.ss"
1.6 | Simple Drawing: "draw.ss"
1.7 | Hangman: "hangman.ss"
1.8 | Managing Control Arrows: "arrow.ss"
1.9 | Manipulating Simple HTML Documents: "docs.ss"
1.10 | Working with Files and Directories: "dir.ss"
1.11 | Graphing Functions: "graphing.ss"
1.12 | Simple Graphical User Interfaces: "gui.ss"
1.13 | An Arrow GUI: "arrow-gui.ss"
1.14 | Controlling an Elevator: "elevator.ss"
1.15 | Queens: "show-queen.ss"
1.16 | Matrix Operations: "matrix.ss"

On this page:

run

top ← prev up next →

#### 1.14`` Controlling an Elevator: "elevator.ss"

The teachpack implements an elevator simulator.

It displays an eight-floor elevator and accepts mouse clicks from the user, which are translated into service demands for the elevator.

( run NextFloor) → any/c
NextFloor : number?

Creates an elevator simulator that is controlled by NextFloor. This function consumes the current floor, the direction in which the elevator is moving, and the current demands. From that, it computes where to send the elevator next.

Example: Define a function that consumes the current state of the elevator (three arguments) and returns a number between 1 and 8. Here is a non-sensical definition:

( define (controller x y z) 7)

It moves the elevator once, to the 7th floor.

Second, set the teachpack to <code>elevator.ss</code>, click RUN, and evaluate
( run controller)
top ← prev up next →