► |  | How to Design Programs Teachpacks

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

▼ | 1 | Ht DP Teachpacks

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

On this page:

run

top ← prev up next →

#### 1.16`` Controlling an Elevator: "elevator.rkt"

(require htdp/elevator)

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.

> > procedure

> > (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 "elevator.rkt", click Run, and evaluate

> (run controller)

top ← prev up next →