;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-reader.ss" "lang")((modname week6_w) (read-case-sensitive #t) (teachpacks ((lib "image.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.ss" "teachpack" "htdp"))))) ;; remove-odds : list-of-numbers -> list-of-numbers ; removes the odd numbers from list (define (remove-odds l) (cond [(empty? l) empty] [else (cond [(odd? (first l)) (remove-odds (rest l))] [else (cons (first l) (remove-odds (rest l)))])] )) ; remove-dolls : list-of-symbols -> list-of-symbols ; remove the dolls from list (define (remove-dolls l) (cond [(empty? l) empty] [else (cond [(symbol=? 'doll (first l)) (remove-dolls (rest l))] [else (cons (first l) (remove-dolls (rest l)))])] )) ; remove-dolls : list-of-symbols -> list-of-symbols ; remove-odds : list-of-numbers -> list-of-numbers ; filter : (X -> boolean) list-of-X -> list-of-X ; removes all elements meeting criteria p? (define (myfilter p? l) (cond [(empty? l) empty] [else (cond [(p? (first l)) (myfilter p? (rest l))] [else (cons (first l) (myfilter p? (rest l)))])] )) (define (is-doll x) (symbol=? x 'doll)) (check-expect (remove-odds (list 1 2 3 4 5)) (list 2 4)) (check-expect (remove-dolls (list 'doll 'truck)) (list 'truck)) (check-expect (myfilter odd? (list 1 2 3 4 5)) (list 2 4)) (check-expect (myfilter is-doll (list 'doll 'truck)) (list 'truck)) ;(check-expect (remove-dolls (list 'doll 'truck)) ; (list 'truck))