On this page:
1 Limitations of artificial intelligence
2 Defining structures
3 Designing functions using structures
8.5

Lecture 8: Structures

This assignment is due on Tuesday, February 1 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.

1 Limitations of artificial intelligence

Exercise 1. Watch Understanding the limitations of AI: when algorithms fail by Timnit Gebru. Focus on how Gebru critiques common beliefs.
  • When you follow the link above with your browser, you should see Gebru’s talk, as well as a button “<” in the upper-right corner. Use the “<” button to expand the annotation sidebar.

  • You may need to log in to Hypothesis, using the account you created in Lecture 5: The table method.

  • Expand the drop-down menu “Public” in the sidebar, and change it to our course group “211”. You belong to this group because you used the invite link in Lecture 5: The table method. If you don’t post to this group, then other students won’t see your annotations, and you won’t get credit.

  • Use the “>” button to collapse the annotation sidebar, then watch the video. The video is synchronized with the automatic and imperfect transcript to the left.

  • Find one place in Gebru’s talk where she questions or disagrees with something that people commonly believe, say, or do. Select the relevant passage in the transcript, and Annotate it like this:
    • “Here Gebru questions the common belief that…” or

    • “Here Gebru disagrees with the common statement that…” or

    • “Here Gebru cautions against the common practice of…”.

    For example, you might add the annotation “Here Gebru disagrees with the common belief that law enforcement should use every tool available” at an appropriate place.

  • Once you have added your annotation, respond to an existing annotation like this:
    • “She does so by describing…” or

    • “She does so by citing…” or

    • “She does so by arguing that…”.

    For example, you might add a response like “She does so by citing a study about…” to an appropriate existing annotation.

  • Don’t bullshit.

2 Defining structures

Exercise 2. 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 2
 
;   (point-x there)
; = (point-x (make-point 70 45))
; = ???
 
;   (point-y here)
; = ???
; = ...
 
;   (person-name you)
; = ???
; = ...
 
;   (point-x me)
; = ???
; = ...
 
;   (make-person "Carol" 21)
; = ???
Show step-by-step calculations by adding comments. Use the Stepper to confirm that your steps are correct.

Exercise 3. 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 4. What are the four courtesy functions for the person structure we defined above? Write down their signatures.

Exercise 5. 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)
; = ???
Show step-by-step calculations by adding comments. Use the Stepper to confirm that your steps are correct.

Exercise 6. 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.)
;   (- (point-x there) (point-x here))
; = ???
; = ...
 
;   (< (person-age me) (person-age you))
; = ???
; = ...
 
;   (point-x (point-x there))
; = ???
; = ...
 
;   (person-age (make-person "Carol" 21))
; = ???
 
;   (make-person (person-name me) (+ 1 (person-age me)))
; = ???
Show step-by-step calculations by adding comments. Use the Stepper to confirm that your steps are correct.

3 Designing functions using structures

Exercise 7. Finish designing the following function.
; 1. Data Definitions
; A Person is (make-person String Number)
(define-struct person [name age])
 
; A Boolean is one of:
; - true
; - false
 
; 2. Signature, Purpose, Header
; teenager? : Person -> Boolean
; is a given person 13-19 years old?
(define (teenager? p) ...)
 
; 3. Examples
; 4. Template
; 5. Definition
; 6. Tests

Optional: Read Chapter 5 of the textbook.