;; 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 15.3.3) (read-case-sensitive #t) (teachpacks ((lib "testing.ss" "teachpack" "htdp"))) (htdp-settings #8(#t constructor repeating-decimal #f #t none #f ((lib "testing.ss" "teachpack" "htdp"))))) ; Worked exercise 15.3.3 ; distance-to-0 : posn -> number (define (distance-to-0 the-point) ; the-point a posn ; (posn-x the-point) a number(x) ; (posn-y the-point) a number(y) ; (sqr (posn-x the-point)) a number (x^2) ; or we could have written ; (* (posn-x the-point) (posn-x the-point)) ; (sqr (posn-y the-point)) a number (y^2) ; (+ (sqr (posn-x the-point)) (sqr (posn-y the-point))) (sqrt (+ (sqr (posn-x the-point)) (sqr (posn-y the-point)))) ) (check-within (distance-to-0 (make-posn 0 0)) 0 .01) (check-within (distance-to-0 (make-posn 6 0)) 6 .01) (check-within (distance-to-0 (make-posn 0 4.3)) 4.3 .01) (check-within (distance-to-0 (make-posn 3 4)) 5 .01) (check-within (distance-to-0 (make-posn 4 7)) (sqrt 65) .01) (generate-report)