;; The first three lines of this file were inserted by DrScheme. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname | 14.1.1|) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
(require installed-teachpacks/picturing-programs)

; Exercise 14.1.1

; Model is a string.

; Draw handler
; show-string : string -> image
(check-expect (show-string "") (text "" 18 "blue"))
(check-expect (show-string "hello") (text "hello" 18 "blue"))
(define (show-string model)
  ; model     a string
  (text model 18 "blue"))

; Tick handler
; chop-string : non-empty-string -> string
(check-expect (chop-string "a") "")
(check-expect (chop-string "hello") "ello")
(define (chop-string model)
  ; model    a string
  (substring model 1))

; Stop checker
; empty-string? : string -> boolean
(check-expect (empty-string? "") true)
(check-expect (empty-string? "m") false)
(check-expect (empty-string? "hello") false)
(define (empty-string? model)
  ; model     a string
  ; ""        a fixed string
  (string=? model ""))

(big-bang "antidisestablishmentarianism"
          (on-draw show-string)
          (on-tick chop-string 1)
          (stop-when empty-string?))
