;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname list_append) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp"))))) ;; list-append: list, list -> list ;; the function takes a list and returns ;; a new list which consists of all the elements ;; of the first list followed by all the elements ;; of the second list ;; Examples: ;; (list-append (cons 3 empty) (cons 5 empty)) -> ;; (cons 3 (cons 5 empty)) ;; (list-append (list 5 6 7) (list 3 6 0)) -> ;; (list 5 6 7 3 6 0) (define (list-append list1 list2) (cond [(empty? list1) list2] [else (cons (first list1) (list-append (rest list1) list2))] ) ) (list-append (list 5 6 7) (list 3 6 0)) ;; expected (list 5 6 7 3 6 0) (list-append empty (list 5 6)) ;; expected (list 5 6) (list-append empty empty) ;; expected empty ;; list-reverse: list -> list ;; the function takes a list and returns a list ;; of the same elements, but in reverse order ;; Example: ;; (list-reverse (list 1 2 3 4 5)) -> (list 5 4 3 2 1) (define (list-reverse a-list) (cond [(empty? a-list) empty] [else (list-append (list-reverse (rest a-list)) (cons (first a-list) empty))] ) ) (list-reverse (list 1 2 3 4 5)) ;; expected (list 5 4 3 2 1)