;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                     ;
;   Here is an example of some lisp code that follows programming     ;
;   by contract style.                                                ;
;                                                                     ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



; Returns the substring of s from positions start to end inclusive.
; If start=end, returns a string of length 1; if start=end+1
; returns the empty string.
; Preconditions: s is a string, start and end are integers
;                0 <= start <= end+1 < (length s)
(defun substring (s start end)
    (cond ( (eq start 0) 
                ; If start is 0, the string to return is at the beginning of s.
                (cond ( (eq end -1) 
                              ; If the string to return is empty, return nil.
                              nil 
                      )
                      ; If it's not, then return the first "end+1"
                      ; characters of s.
                      ; Could recurse on end, but prefix does that for us.
                      ( t (prefix s (+ end 1)) )
                )
          ) 
          ; Start isn't zero, so recurse down the string until we
          ; find the start of the substring.
          ( t   (substring (cdr s) (- start 1) (- end 1)) )
    )
)