1
(define-struct animal (name species age breakfasthour dinnerhour))
(define-struct attendant (name a1 a2 a3))


(define gorilla (make-animal "Koko" "Gorilla" 4 "8" "10"))
(define bat (make-animal "Bruce" "Bat" 1 "23" "5"))
(define mandrill (make-animal "Manny" "Mandrill" 5 "8" "7"))
(define crocodile (make-animal "Swampy" "Crocodile" 1 "10" "8"))
(define ocelot (make-animal "Ozzy" "Ocelot" 7 "7" "17"))
(define capybara (make-animal "Capy" "Capybara" 4 "6" "8"))
(define potto (make-animal "Spot" "Potto" 2 "2" "6"))
(define tapir (make-animal "Stripey" "Tapir" 3 "10" "6"))
(define vulture (make-animal "Beaky" "Vulture" 10 "9" "6"))


(define attendant1 (make-attendant "Dave" gorilla bat mandrill))
(define attendant2 (make-attendant "John" crocodile ocelot capybara))
(define attendant3 (make-attendant "Joe" potto tapir vulture))

我需要一个函数来接收动物并返回它的进餐时间,如果我吃大猩猩,那么晚餐时间是 10 点。这就是我所做的。忽略上面数字上的引号。

(define (meal-time? e1 e2)
  (string=? (animal-species e1)
            (animal-dinnerhour e2)))

它运行,但 wnt 给我一个输出。为什么它不会给我一个输出?

编辑-(meal-time? gorilla 10)告诉我它需要一个动物,但给出了 10。

4

1 回答 1

2

你的meal-time?函数接受两个动物作为参数(因为你animal-在两个参数上都使用了访问器函数),但是你用一个动物和一个数字来调用它。因此,您会收到一条错误消息,告诉您第二个参数应该是动物。

如果你用两只动物作为参数调用你的函数,你就不会再得到错误了。你会得到#f. 你的函数所做的是:它检查第一个动物的物种是否等于第二个动物的晚餐时间。既然没有物种的名字是数字,那永远不会是真的。

于 2013-01-29T02:35:12.620 回答