8.7

### Lecture 8: Structures

This assignment is due on Tuesday, January 31 at 11:59pm. Submit it using Handin as assignment lecture8.

Remember to follow the design recipe whenever you design or write a function. In particular, every type mentioned in a signature must be introduced by a data definition, except for these well-known types: Number, Image, String, Color, Boolean. #### 1Defining structures

Exercise 1. Copy the definitions below into your Definitions Window. Make sure you know which lines are data definitions, which lines are structure definitions, and which lines are constant definitions.
 ; A Point is (make-point Number Number) (define-struct point [x y]) (define here  (make-point 30 50)) (define there (make-point 70 45)) ; A Person is (make-person String Number) (define-struct person [name age]) (define me  (make-person "Alice" 37)) (define you (make-person "Bob"   22))
Then, copy the expressions below into your Definitions Window. What are their results? Try to predict the results before asking DrRacket. (If it runs into an error, write “error” after the last step.)
 ; Exercise 1 ;   (point-x there) ; = (point-x (make-point 70 45)) ; = ??? ;   (point-y here) ; = ??? ; = ... ;   (person-name you) ; = ??? ; = ... ;   (point-x me) ; = ??? ; = ... ;   (make-person "Carol" 21) ; = ???

Exercise 2. Here are the four courtesy functions for the point structure we defined above. Write down their signatures.
 make-point point-x point-y point?

Exercise 3. What are the four courtesy functions for the person structure we defined above? Write down their signatures.

Exercise 4. Copy the expressions below into your Definitions Window. What are their results? Try to predict the results before asking DrRacket.
 ;   (person? me) ; = ??? ; = ... ;   (person? "Alice") ; = ??? ;   (person? there) ; = ???