CS 1102: Accelerated Intro to Program Design
Documentation and Data Definition Example

A data definition with examples of the data

;; a coordinate is (make-coordinate number number)
(define-struct coordinate (x y))

;; Examples of coordinates
(make-coordinate 0 8)
(make-coordinate -1 4)

A program with a contract, purpose, and test cases

;; move-coordinate-vertical : coordinate number -> coordinate
;; consumes a coordinate and a number by which to move the coordinate in the
;;   vertical position and produces a coordinate in the new position.
(define (move-coordinate-vertical a-coordinate delta)
  (make-coordinate (coordinate-x a-coordinate) 
	           (+ (coordinate-y a-coordinate) delta)))

;; Test cases
(check-expect (move-coordinate-vertical (make-coordinate 0 8) 5)
              (make-coordinate 0 13))
(check-expect (move-coordinate-vertical (make-coordinate 4 -2) 7)
              (make-coordinate 4 5))
(check-expect (move-coordinate-vertical (make-coordinate -1 4) -4)
              (make-coordinate -1 0))