0
;; definition of the structure "book"
;; author: string - the author of the book
;; title: string - the title of the book
;; genre: symbol - the genre
(define-struct book (author title genre))
(define lotr1 (make-book "John R. R. Tolkien"
"The Fellowship of the Ring"
'Fantasy))
(define glory (make-book "David Brin"
"Glory Season"
'ScienceFiction))
(define firstFamily (make-book "David Baldacci"
"First Family"
'Thriller))
(define some-books (list lotr1 glory firstFamily))
;; count-books-for-genre: symbol (list of books) -> number
;; the procedure takes a symbol and a list of books and produces the number
;; of books from the given symbol and genre
;; example: (count-books-for-genre 'Fantasy some-books) should produce 1
(define (count-books-for-genre genre lob)
(if (empty? lob) 0
(if (symbol=? (book-genre (first lob)) genre)
(+ 1 (count-books-for-genre (rest lob) genre))
(count-books-for-genre (rest lob) genre)
)
)
)
(count-books-for-genre 'Fantasy some-books)
它產生以下異常第一:非空類型的預期參數;鑑於'幻想,我不明白什麼是問題。方案結構問題
有人可以給我一些解釋嗎?
非常感謝!