Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 1.59 KB | None | 0 0
  1.  
  2. ;; =================
  3. ;; Data definitions:
  4.  
  5. ;; Light is one of:
  6. ;;  - "red"
  7. ;;  - "yellow"
  8. ;;  - "green"
  9. ;; interp. the current color of the light
  10. ;; <examples are redundant for enumerations>
  11.  
  12. #;
  13. (define (fn-for-light l)
  14.   (cond [(string=? l "red")    (...)]
  15.         [(string=? l "yellow") (...)]
  16.         [(string=? l "green")  (...)]))
  17.  
  18. ;; Template rules used:
  19. ;;   one of: 3 cases
  20. ;;   atomic distinct: "red"
  21. ;;   atomic distinct: "yellow"
  22. ;;   atomic distinct: "green"
  23.  
  24.  
  25.  
  26. ;; =================
  27. ;; Functions:
  28.  
  29. ;; Light -> Light
  30. ;; called to run the animation; start with (main "red")
  31. ;; no tests for main function
  32. (define (main l)
  33.   (big-bang l
  34.             (on-tick next-color 1)   ; Light -> Light
  35.             (to-draw render-light))) ; Light -> Image
  36.  
  37.  
  38.  
  39.  
  40. ;; Light -> Light
  41. ;; produce next color of light
  42. (check-expect (next-color "red")    "green")
  43. (check-expect (next-color "yellow") "red")
  44. (check-expect (next-color "green")  "yellow")
  45.  
  46. #;
  47. (define (next-color l)      ; stub
  48.   "red")
  49. ;<template from Light>
  50.  
  51. (define (next-color l)
  52.   (cond [(string=? l "red")    "green"]
  53.         [(string=? l "yellow") "red"]
  54.         [(string=? l "green")  "yellow"]))
  55.  
  56.  
  57.  
  58. ;; Light -> Image
  59. ;; produce appropriate image for light color
  60. (check-expect (render-light "red")    RON)
  61. (check-expect (render-light "yellow") YON)
  62. (check-expect (render-light "green")  GON)
  63.  
  64. #;
  65. (define (render-light l)
  66.   BACKGROUND)
  67. ;<template from Light>
  68.  
  69. (define (render-light l)
  70.   (cond [(string=? l "red")    RON]
  71.         [(string=? l "yellow") YON]
  72.         [(string=? l "green")  GON]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement