Comp 210 Lab 4: Non-empty Lists of Numbers

Solution 1: The base case should describe all lists of length one, the shortest possible non-empty lists:

     ; A non-empty list of numbers (nelo-numbers) is one of
     ;   - (cons f empty)
     ;     where f is a number
     ;   - (cons f r)
     ;     where f is a number, r is a nelo-numbers

Solution 2: Use the definition of lists-of-numbers that we already know.

     ; A non-empty list of numbers (nelo-numbers) is
     ;   (cons f r)
     ;   where f is a number, r is a list-of-numbers

When you develop programs, you should use the template corresponding to the definition you choose.

  1.      (define (f nelon)
            (cond
               [(empty? (rest nelon)) ...(first nelon)...]
               [else                  ...(first nelon)...(f (rest nelon))...]))
         

  2.      (define (f nelon)
            ...(first nelon)...(rest nelon)...)
         
    where f probably calls another function on (rest nelon) that consumes a list of numbers, not just a non-empty list of numbers.

The first choice is usually the better option.