; ; The standard Scheme function "reverse" reverses the top level elements ; in a list. ; ; The "deep-reverse" function below recursively descends and sublists and ; reverses them as well. ; ; (define (deep-reverse l) (if (null? l) '() (append (deep-reverse (cdr l)) (list (if (list? (car l)) (deep-reverse (car l)) (car l)))))) ; ; This function performs the same as above, but the second argument to ; "append" is generated a little differently. (This is what I originally ; wrote on the board.) ; (define (deep-reverse-2 l) (if (null? l) '() (append (deep-reverse (cdr l)) (if (list? (car l)) (list (deep-reverse (car l))) (list (car l))))))