;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname 11.2.1) (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"))))) ;A natural-number is ;1. 0 or ;2. (add1 n) where n is a natural-number. ; ;A list-of-symbols is ;1. an empty list or ;2. (cons s los) where s is a symbol and ;los is a list-of-symbols. ; ;repeat : natural-number symbol -> list-of-symbols ;Given a natural-number n, returns word n times ;as a list-of-symbols. ; ;Template ;(define (repeat n word) ; (cond ; [(zero? n) ...] ; [else ... (repeat (sub1 n)) ...])) (define (repeat n word) (cond [(zero? n) empty] [else (cons word (repeat (sub1 n) word))])) ;; f : number -> number (define (f x) (+ (* 3 (* x x)) (+ (* -6 x) -1))) ; ;A list-of-posns is either ;1. an empty list or ;2. (cons p lop) where p is a posn and lop is a list-of-posns. ;tabulate-f : natural-number -> list-of-posns ;Creates a "table". Returns a list of n posns of the form ;(cons (make-posn (f n) n) (cons (make-posn (f (- n 1) (- n 1)))... (define (tabulate-f n) (cond [(zero? n) empty] [else (cons (make-posn (f n) n) (tabulate-f (sub1 n)))]))