scheme struct question

Posted by qzar on Stack Overflow See other posts from Stack Overflow or by qzar
Published on 2010-04-30T23:05:02Z Indexed on 2010/04/30 23:07 UTC
Read the original article Hit count: 353

Filed under:
;; 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)

It produce following exception first: expected argument of type non-empty list; given 'Fantasy, I don't understand whats the problem.

Can somebody give me some explanation ?

Thank you very much !

© Stack Overflow or respective owner

Related posts about Scheme