;; 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-lambda-reader.ss" "lang")((modname higherOrder) (read-case-sensitive #t) (teachpacks ((lib "docs.rkt" "teachpack" "htdp"))) (htdp-settings #(#t write repeating-decimal #f #t none #f ((lib "docs.rkt" "teachpack" "htdp")) #f))) (define (f g x) (g x)) (define incr (lambda (n) (+ 1 n))) (incr 5) (define double (lambda(n) (* 2 n))) (double 5) (double 10) (define (mapp f ys) (if (null? ys) '() (cons (f (car ys)) (mapp f (cdr ys))))) (mapp incr '(1 2 3 )) ; this is the function from our notes (mapp double '(1 2 3)) ; this is the built-in map function (map incr '(4 5 6)) (define (atomcnt3 s) (cond ((atom? s) 1) (else (apply + (map atomcnt3 s))))) (atomcnt3 '(1 2 3)) (atomcnt3 '((1) (2 (3)) 4 (((5))))) (define (foldrr op ys id) (if (null? ys) id (op (car ys)(foldrr op (cdr ys) id)))) (foldrr + '(1 2 3 4 5) 0) (foldrr * '(1 2 3 4) 1) (foldrr append '((1 2) (3 4))'()) (define (sum f ys) (foldrr + (map f ys) 0)); applies f to each list element and then sums the results (sum incr '(1 2 3)) (sum double '(4 5 6 7))