0
(define-struct restaurant (name address  lod))
(define-struct dish  (name main-ingredient price))

(define lod
  (list
   (make-dish "BNC" "pepper" 15.00)
   (make-dish  "BBQ" "sauce" 20.00)
   (make-dish "BAW" "vanilla" 18.00)
    (make-dish "ACA" "tomato" 15.00)
   (make-dish  "NAM" "onions" 25.00)
   (make-dish "PLA" "milk" 34.00)))

(define lod1
  (list
   (make-dish "AHSH" "carrots" 23.00)
   (make-dish  "PROA" "garlic" 21.00)
   (make-dish "MENE" "eggs" 16.00)
    (make-dish "SAYB" "water" 11.00)
   (make-dish  "WAFA" "chicken" 22.00)
   (make-dish "LDAFK" "chocolate" 10.00)))


(define Sky-Dragon (make-restaurant "Sky Dragon" "23 Cutoiut, NY"  lod))
(define Tomas (make-restaurant "Tomas" "34 Rossi, CA" lod1))


(define restaurant1 Sky-Dragon)
(define restaurant2 Tomas)

我想知道你将如何编写一个函数来消费一家餐厅并产生餐厅的菜肴总数。就像我去餐厅 1 一样,我得到了 6 道菜。希望我做对了。

4

1 回答 1

1

很简单,只需使用存取程序来检索餐厅的菜肴列表,然后使用内置程序来确定该列表的大小(或“长度”):

(define (number-of-dishes restaurant)
  (<???>                  ; how do we determine the size of a list?
    (<???> restaurant)))  ; how do we access a restaurant's list of dishes?

我会让您弄清楚细节,但请记住 - 每当您使用 定义新结构时define-struct,都会自动为其每个字段创建一个访问器过程。例如,pricea 的 adish是通过调用dish-pricea获得的dish: (dish-price dish)

于 2013-02-17T05:02:16.333 回答