0

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?

soegaard
  • 30,661
  • 4
  • 57
  • 106
Mr. Lisp
  • 3
  • 3

1 Answers1

4

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.

Óscar López
  • 232,561
  • 37
  • 312
  • 386