On this page:
run

1.16 Controlling an Elevator: "elevator.rkt"🔗ℹ

 (require htdp/elevator) package: htdp-lib

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)