;; 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-intermediate-reader.ss" "lang")((modname 21.1.3) (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"))))) Exercise 21.1.3. Define natural-f, which is the abstraction of the following two functions: ;; copy : N X -> (listof X) ;; to create a list that contains ;; obj n times (define (copy n obj) (cond [(zero? n) empty] [else (cons obj (copy (sub1 n) obj))])) ;; n-adder : N number -> number ;; to add n to x using ;; (+ 1 ...) only (define (n-adder n x) (cond [(zero? n) x] [else (+ 1 (n-adder (sub1 n) x))])) Don't forget to test natural-f. Also use natural-f to define n-multiplier, which consumes n and x and produces n times x with additions only. Use the examples to formulate a contract. Hint: The two function differ more than, say, the functions sum and product in exercise 21.1.2. In particular, the base case in one instance is a argument of the function, where in the other it is just a constant value. Solution