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-beginner-reader.ss" "lang")((modname 11.2.3) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp")))))
4 ;A natural-number is
5 ;1. 0 or
6 ;2. (add1 n) where n is a natural-number.
7 ;
8 ;A list-of-symbols is
9 ;1. an empty list or
10 ;2. (cons s los) where s is a symbol and
11 ;los is a list-of-symbols.
12 ;
13 ;repeat : natural-number symbol -> list-of-symbols
14 ;Given a natural-number n, returns word n times
15 ;as a list-of-symbols.
16 ;
17 ;Template
18 ;(define (repeat n word)
19 ; (cond
20 ; [(zero? n) ...]
21 ; [else ... (repeat (sub1 n)) ...]))
23 (define (repeat n word)
24 (cond
25 [(zero? n) empty]
26 [else (cons word (repeat (sub1 n) word))]))
28 ;; f : number -> number
29 (define (f x)
30 (+ (* 3 (* x x))
31 (+ (* -6 x)
32 -1)))
33 ;
34 ;A list-of-posns is either
35 ;1. an empty list or
36 ;2. (cons p lop) where p is a posn and lop is a list-of-posns.
37 ;tabulate-f : natural-number -> list-of-posns
38 ;Creates a "table". Returns a list of n posns of the form
39 ;(cons (make-posn (f n) n) (cons (make-posn (f (- n 1) (- n 1)))...
41 (define (tabulate-f n)
42 (cond
43 [(zero? n) empty]
44 [else (cons (make-posn (f n) n) (tabulate-f (sub1 n)))]))