CS 9-2 Chapter 5 Quiz Question: Write a function such that when given a non-empty list of numbers, it will return the largest number on the list. For example, (max-lst '(5 10 9 6 2)) will return 10. (max-lst '(2)) will return 2. Hint: First, try to write a function that given 2 numbers, will return the larger of the two numbers. Let's call it max2. Here is the skeleton. (define max2 (lambda (a b) (your comparison function) )) (max2 5 10) > 10 Then, think about if you have an arbitrary list, e.g. (5 10 3 2 9), how would you go about finding the largest number of the list? Break the problem down into a smaller question. You just wrote max2, which finds the larger of the two numbers. Now, what is the larger number between 5 and the first number of the rest of the list (10 3 2 9)? It's 10. Then what is the larger number between 10 and the first number of the rest of the list? So on and so forth. Here is some Scheme help. List: Examples of list in Scheme: (1 2 3), (a b c), (1 b) We call things in the list elements, since they can be integers, alphabets, words or anything. Just like in math, elements in a list do not have to be of the same type. '() is an empty list. You can check whether a list is an empty list by the function empty? for example: (empty? '(1 2 3)) will return #f which means false. (empty? '()) will return #t which means true. '() is different from ( ) without the tick. If Scheme sees a tick, it does not evaluate the elements inside the list. However, without the tick, Scheme will evaluate the list. Operators: The first element of the list should always be an operator, e.g. mathematical operators such as +, -, *, /, or list operators such as car, cdr, cadr and empty? Therefore, you should write 1+2 as (+ 1 2), not (+ 1 2), (1+2), (+ (1 2)) or (+ 1 2). Similarly, if you want to express if a is bigger than b, then return 1, or else return 0, you write (if (> a b) 1 0) List operators: (car (1 2 3)) will return the first element of a list. In this example, it will return integer 1 (cdr (1 2 3)) will return the a list containing everything but the first element of the list. In this example, it will return list (2 3) (car (cdr (1 2 3))) is equivalent to (cadr (1 2 3)) and will return 2 (cdr (car (1 2 3))) will return an error. Because (car (1 2 3)) returns 1 and cdr only works on lists.