I took the following question from HTDP2e (exercise 65):
Exercise 65. Take a look at the following structure type definitions:
(define-struct movie [title producer year])
Write down the names of the functions (constructors, selectors, and predicates).
My Answer is:
make-movie is a constructor. movie? is a predicate. movie-title, movie-producer, and movie-year are selectors. So
(define-struct movie [title producer year])
(define-struct M-1
(make-movie "Parasite" "Bong Joon-ho" "2019"))
(movie-title M-1) ; Parasite
(movie-producer M-1) ;Bong Joon-ho
(movie-year M-1) ; 2019
But I got an error: "define-struct: expected a field name, but found a string" Can you help me? How can I edit my codes?
This line:
(define-struct M-1
(make-movie "Parasite" "Bong Joon-ho" "2019"))
Should be:
(define M-1
(make-movie "Parasite" "Bong Joon-ho" "2019"))
You're no longer defining a struct, just a variable that holds a struct.