;; 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-advanced-reader.ss" "lang")((modname lect05a) (read-case-sensitive #t) (teachpacks ((lib "world.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "world.ss" "teachpack" "htdp"))))) ; map : (-> (-> alpha beta) (list-of alpha) (list-of beta)) ; (define (mymap f data) (cond [(empty? data) empty] [(cons? data) (cons (f (first data)) (mymap f (rest data))) ])) (check-expect (mymap sqr empty) empty) (check-expect (mymap (lambda (x) (+ x 1)) (list 3)) (list 4)) (check-expect (mymap sqr (list 3 4 5)) (list 9 16 25)) (define (add-in-list data) (cond [(empty? data) 0] [(cons? data) (+ (first data) (add-in-list (rest data)))])) (define (my-foldl build-answer init-val data) (cond [(empty? data) init-val] [(cons? data) (build-answer (first data) (my-foldl build-answer init-val (rest data)))]))