(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)
I would like to know how would you write a function that consumes a restaurant and produces the total number of dishes the restaurant has. Like I take restaurant1, I get 6 dishes. Hope I am doing this right.
It’s simple, just use the accessor procedure to retrieve the list of dishes of a restaurant, and then the built-in procedure to determine the size (or “length”) of that list:
I’ll let you figure out the details, but remember – whenever you define a new struct using
define-struct, an accessor procedure is automatically created for each of its fields. For example, thepriceof adishis obtained by callingdish-priceon adish:(dish-price dish).