Here is a data definition for lists of numbers that always have at least one number in them:

A non-empty-lon is either:
  - (cons number empty)
  - (cons number non-empty-lon)

Write the function max : non-empty-lon -> number. It computes the maximum number in a list of numbers, without assuming that the numbers are all positive.

Solution

(define (max nelon)
  (cond
    [(empty? (rest nelon)) (first nelon)]
    [else (max-num (first nelon) (max (rest nelon)))]))
    
;; max-num : number number -> number
(define (max-num a b)
  (cond
    [(< a b) b]
    [else a]))