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-advanced-reader.ss" "lang")((modname |29.3|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 ;norm : vector -> number
5 ;Produces the square root of the sum of the numbers in avector.
7 (define (norm avector)
8 (sqrt (sum-of-squares avector 0)))
10 ;sum-of-squares : vector N -> number
11 ;Given avector and i, square the element in avector from [i,vector-length) and then sum them
13 (define (sum-of-squares avector i)
14 (cond
15 [(= (vector-length avector) i) 0]
16 [else (+ (sqr (vector-ref avector i))
17 (sum-of-squares avector (add1 i)))]))
19 ;vector-contains-doll? : (vectorof symbols) -> boolean
20 ;Given avector, determine if it contains 'doll.
22 (define (vector-contains-doll? avector)
23 (vector-contains-doll?-aux avector 0))
25 ;vector-contains-doll?-aux : (vectorof symbols) N -> boolean
26 ;Given avector and i, determine if avector contains 'doll.
28 (define (vector-contains-doll?-aux avector i)
29 (cond
30 [(= (vector-length avector) i) false]
31 [else (or (symbol=? (vector-ref avector i) 'doll)
32 (vector-contains-doll?-aux avector (add1 i)))]))
33 (define vector2 (vector 'robot
34 'car
35 'eraser
36 'pen
37 'motorcycle
38 'bicycle
39 'helmet
40 'monitor
41 'dolly
42 'policeman
43 'diamond))
44 (vector-contains-doll? vector2)