current-inventory
is a list of these inventory
records, representing all items for sale. Define this placeholder with a
list of several records.
Write the procedure new-item!, which consumes the name of an
item, its price, and the number of copies that arrived from the warehouse.
It extends the current-inventory
appropriately. That is, if
the item is already in the database, it modifies the corresponding record;
otherwise it adds an appropriate record.
Write the procedure inflate!, which consumes a percentage and
increases the price of each item in current-inventory
accordingly.
Write the procedure discontinued!, which consumes the name of an item and removes the item from the list.
The implementation requires two procedures:
(begin (next!) (next!) (next!))should cycle the traffic light through all three states back to whatever was its intial state.
Here are the three stages:
![]() | ![]() | ![]() |
They were produced with the following constants:
;; --------------------------------------------------------- ;; Basic constanst: (define WIDTH 50) (define HIGHT 160) (define RADIUS 20) (define DELTA 10) (define X (quotient WIDTH 2)) ;; off-set : num -> num (define (off-set y) (+ y DELTA (* 2 RADIUS))) (define Y:RED (off-set (- RADIUS))) (define Y:YEL (off-set Y:RED)) (define Y:GRN (off-set Y:YEL)) ;; A light is (make-light posn color) (define-struct light (center color)) (define RED:LIGHT (make-light (make-posn X Y:RED) RED)) (define YEL:LIGHT (make-light (make-posn X Y:YEL) YELLOW)) (define GRN:LIGHT (make-light (make-posn X Y:GRN) GREEN))You may find the following cute:
;; cycle : -> void ;; effect: cycle through the three colors, with one-second breaks (define (cycle) (next) (sleep 1) (cycle)) (init) (cycle)