Guided Practice 2.1 - Solution

The question was: In this example

;; ball-after-tick : Ball -> Ball
;; GIVEN: The state of a ball b
;; RETURNS: the state of given ball at the next tick
;; STRATEGY: cases on whether ball would hit the wall on 
;; the next tick

(define (ball-after-tick b)
  (if (ball-would-hit-wall? b)
    (ball-after-bounce b)
    (ball-after-straight-travel b)))
What should be the contract and purpose statement for ball-after-bounce and ball-after-straight-travel?

Each of these is a good place to use WHERE clauses to distinguish functions with similar purposes. Here's one solution:

;; ball-after-bounce : Ball -> Ball
;; GIVEN: The state of a ball b
;; WHERE: the ball will bounce on the next tick
;; RETURNS: the state of given ball at the next tick

;; ball-after-straight-travel : Ball -> Ball
;; GIVEN: The state of a ball b
;; WHERE: the ball does not bounce on the next tick
;; RETURNS: the state of given ball at the next tick

Last modified: Tue Jul 26 22:01:37 Eastern Daylight Time 2016