;; 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 week6_m_full) (read-case-sensitive #t) (teachpacks ((lib "image.ss" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.ss" "teachpack" "2htdp"))))) ; write the function addntoall, which adds n to every ; number in a given list ; addntoall : number list-of-numbers -> list-of-numbers ; adds given number to each element of list (define (addntoall n lon) (map (lambda (x) (+ n x)) lon) ) (check-expect (addntoall 5 (list 1 2 3)) (list 6 7 8)) (check-expect (addntoall 0 empty) empty) ; foldr : (X Y -> Y) Y list-of-X -> Y ; (foldr + 0 (list 1 2 3)) ---> 6 ; (foldr * 1 (list 2 3 4)) ---> 24 ; (number number -> number) number list-of-numbers -> number ; (foldr first-doll-or-else false (list 'cheese 'doll 'car)) ; (symbol boolean -> boolean) boolean list-of-symbols -> boolean ; signature of foldr? (define (drop p? l) (filter (negate p?) l)) (define (negate p) (local [(define (negated-predicate x) (not (p x)))] negated-predicate)) (define mycons2 (cons 'banana (cons 'apple empty))) (define (f x) (* x 3)) ; is equivalent to: ;(define f (lambda (x) (* x 3))) (f 4) (define adder (lambda (x) (lambda (y) (+ x y)))) ; signature? ; adder : number -> (number -> number) (define xx (adder 3)) ( 5)