;; define a function that takes n and returns n^2 + n + 1: (define (f n) (+ (* n n) n 1)) ;; test 1: (f 2) ;; expected result: 7 ;; test 2: (f -2) ;; expected result: 3 ;; Exercise 2.2.5 ;; http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-5.html#node_sec_2.2 ;; write the expressions and the tests, then test them. ;; Programs for word problems ;; define constant PI (define PI 3.14) ;;;;;;;;;;; Function definition with a contract, etc. ;;;;;;;;;;;;;; ;; Contract: area-of-disk : number -> number ;; Example: (area-of-disk 1) produces 3.14 ;; Purpose: to compute the area of a disk whose radius is r (define (area-of-disk r) (* PI (* r r))) (area-of-disk 1) ;; Test ;; expected value 3.14 3.14 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Contract: area-of-ring : number number -> number ;; Purpose: to compute the area of a ring whose radius is ;; outer and whose hole has a radius of inner ;; Example: (area-of-ring 5 3) should produce 50.24 ; Definition: [the function written in Scheme] (define (area-of-ring outer inner) (- (area-of-disk outer) (area-of-disk inner))) ;; Tests: (area-of-ring 5 3) ;; expected value 50.24 ;; Exercise 2.3.1 ;; http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-5.html#node_sec_2.3 ;; Exercise 2.3.3