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 21.2.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 (local ((define (f x) x))
5 (build-list 4 f))
7 (local ((define (f x) (+ 1 x)))
8 (build-list 4 f))
10 (local ((define (f x)
11 (expt 10 (* -1
12 (+ x 1)))))
13 (build-list 4 f))
15 ;evens : N [>=0] -> (listof N [>=0])
16 Given n, evens creates a list of the first n even numbers.
18 (define (evens n)
19 (local ((define (evens n)
20 (build-list n f))
21 (define (f n)
22 (* 2
23 (+ 1 n))))
24 (evens n)))
27 Exercise 21.2.1. Use build-list
29 to define evens, which consumes a natural number n and creates the list of the first n even numbers;
31 to define tabulate from exercise 21.1.1; and
33 to define diagonal, which consumes a natural number n and creates a list of lists of 0 and 1.
34 Example:
36 (equal? (diagonal 3)
37 (list
38 (list 1 0 0)
39 (list 0 1 0)
40 (list 0 0 1)))
41 Use local if function definitions require auxiliary functions. Solution
43 ;; build-list : N (N -> X) -> (listof X)
44 ;; to construct (list (f 0) ... (f (- n 1)))
45 (define (build-list n f) ...)