; differences
; > (differences '(2 5 -7 3))
; (3 -12 10)

(define (differences sent)
  (cond ((< (count sent) 2) '())
        (else (se (- (second sent) (first sent))
                  (differences (bf sent))))))
; I prefer a function called "second" for this problem
; because it perfectly describes the element in the sentence
; being used for doing subtraction. You can use (first (bf sent))
; or (item 2 sent), but this is a situation where readability
; seems to work better. 
(define (second sent)
  (first (bf sent)))

; merge
; > (merge '(1 5 5 6 7) '(3 4))
; (1 3 5 5 5 6 7)

; Doing this by hand can help to understand how to set up this problem:
; > (merge '(1 5 5 6 7) '(3 4)) becomes
;   (se 1 (merge '(5 5 6 7) '(3 4))) becomes
;   (se 1 (se 3 (merge '(5 5 6 7) '(4)))) becomes
;   (se 1 (se 3 (se 4 (merge '(5 5 6 7) '())))) becomes
;   (se 1 (se 3 (se 4 '(5 5 6 7))))
; at which point the se functions kick in and the final result is
; produced. Note that the base case was when one of the sentences
; was empty, at which point the other sentence was returned.

(define (merge s1 s2)
  (cond ((empty? s1) s2)
        ((empty? s2) s1)
        ; ((or (empty? s1) (empty? s2)) (se s1 s2))
        ((< (first s1) (first s2))
         (se (first s1) (merge (bf s1) s2)))
        (else
         (se (first s2) (merge s1 (bf s2))))))

; toBinary
; > (toBinary 91)
; 1011011

; Here is a trace of the calls to (toBinary 91). The calls come from
; dividing by 2 and taking the floor. The return values come from
; combining the remainders.
(define (toBinary n)
  (cond ((< n 2) n)
        (else (word 
               (toBinary (floor (/ n 2)))  ; the recursive call comes
               (remainder n 2)))))         ; before the remainder!