1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #reader(lib "htdp-advanced-reader.ss" "lang")((modname |36.4|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 12687dd9 2023-08-04 jrmu ;A traffic-light color (TL-color) is either
6 12687dd9 2023-08-04 jrmu ;2. 'yellow, or
9 12687dd9 2023-08-04 jrmu ;;State Variable:
10 12687dd9 2023-08-04 jrmu ;;current-color : TL-color
11 12687dd9 2023-08-04 jrmu (define current-color 'red)
13 12687dd9 2023-08-04 jrmu ;next : -> void
14 12687dd9 2023-08-04 jrmu ;Effect: Changes current-color from 'red to 'green, 'green to 'yellow, or 'yellow to 'red depending on what the current-color is. Produces no output.
16 12687dd9 2023-08-04 jrmu (define (next)
17 12687dd9 2023-08-04 jrmu (set! (next-color current-color)))
19 12687dd9 2023-08-04 jrmu ;next-color : TL-color -> TL-color
20 12687dd9 2023-08-04 jrmu ;Given acolor, returns the next logical color.
22 12687dd9 2023-08-04 jrmu (define (next-color acolor)
24 12687dd9 2023-08-04 jrmu [(symbol=? acolor 'red) 'green]
25 12687dd9 2023-08-04 jrmu [(symbol=? acolor 'yellow) 'red]
26 12687dd9 2023-08-04 jrmu [(symbol=? acolor 'green) 'yellow]))