-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-5-4.rkt
48 lines (31 loc) · 1.48 KB
/
1-5-4.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
;; The first three lines of this file were inserted by DrRacket. 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 1-5-4) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))
(define-struct movie [title producer year])
(define-struct person [name hair eyes phone])
(define-struct pet [name number])
(define-struct CD [artist title price])
(define-struct sweater [material size producer])
; exercise 66
(define my-sweater (make-sweater "cotton" "large" "hm"))
(sweater-material my-sweater)
(sweater-size my-sweater)
(sweater-producer my-sweater)
(sweater? my-sweater)
(define-struct entry [name phone email])
(define-struct ball [location velocity])
(define SPEED 3)
(define-struct balld [location direction])
(make-balld 10 "up")
; This assumes that all instances of balld move at the same speed
; but perhaps in different directions and at different locations
(define-struct vel [deltax deltay])
(define ball1
(make-ball (make-posn 30 40) (make-vel -10 5)))
; Exercise 68
(define-struct ballf [x y deltax deltay])
(define ball2 (make-ballf 30 40 -10 5))
(check-expect (ballf-x ball2) (posn-x (ball-location ball1)))
(check-expect (ballf-y ball2) (posn-y (ball-location ball1)))
(check-expect (ballf-deltax ball2) (vel-deltax (ball-velocity ball1)))
(check-expect (ballf-deltay ball2) (vel-deltay (ball-velocity ball1)))