Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-intermediate-reader.ss" "lang")((modname 20.1.1) (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")))))
4 #|
6 (define (f x) x)
8 (cons f empty)
10 (f f)
12 (cons f (cons 10 (cons (f 10) empty)))
14 |#
16 (define (f x) f)
18 #|
19 Exercise 20.1.3. Develop a-function=?. The function determines whether two functions from numbers to numbers produce the same results for 1.2, 3, and -5.7.
21 Can we hope to define function=?, which determines whether two functions (from numbers to numbers) are equal? Solution
22 |#
24 ;a-function=? (number -> number) (number -> number) (listof ITEM) -> boolean
25 ;Determines whether func1 and func2 are equal by evaluating applying the functions to aloi (listof ITEM).
27 (define (a-function=? func1 func2 aloi)
28 (cond
29 [(empty? aloi) true]
30 [(cons? aloi) (and (equal? (func1 (first aloi))
31 (func2 (first aloi)))
32 (a-function=? func1 func2 (rest aloi)))]))
34 (define list1 '(1.2 3 -5.7))
36 ;function-1: number -> number
37 ;Returns 0 (ie, f(x) = 0).
38 (define (function-1 x)
39 0)
41 ;function-2: number -> number
42 ;f(x) = (x-1.2)*(x-3)(x+5.7)
44 (define (function-2 x)
45 (* (- x 1.2)
46 (- x 3)
47 (+ x 5.7)))
49 ;function-3 : number -> number
50 ;f(x) = x.
52 (define (function-3 x)
53 x)
55 (a-function=? function-1 function-2 list1)
56 (not (a-function=? function-1 function-3 list1))
57 (not (a-function=? function-2 function-3 list1))
59 ;sort : (listof numbers) (number number -> boolean) -> (listof numbers)
61 ;map : (number -> number) (listof numbers) -> (listof numbers)
63 ;project : (listof (listof symbols)) ((listof symbols) -> symbols) -> symbols