The following code fragments were from problem sets or exams that your classmates handed in earlier this semester. (The identifiers have been changed to protect the innocent.) For each code fragment, explain why the code is either inefficient, inelegant, or both, and suggest how the student should have written the code.
(define (foo x) (if x x #f))
(define (baz z) (map (lambda (x) (add1 x)) z))
(define (blah w) (append (list 3) w))
(define (bar x) (if (= (length x) 0) (error "list is empty!") (head x)))
(define (f q x) (if (empty? x) #f (if (empty? (tail x)) #f (if (q (head x) (head (tail x))) #t (if (empty? (tail (tail x))) #f (f q (tail x)))))))
(define (g x) (if (> (length x) 200) (- (length x) 1) 0))