Exercise 193: Take a look at this data definition:
; A [Bucket ITEM] is ; (make-bucket N [List-of ITEM]) ; interp. the n in (make-bucket n l) is the length of l ; i.e., (= (length l) n) is always true
When you instantiate Bucket with String, IR, and Posn, you get three different data collections. Describe each of them with a sentence and with two distinct examples.
Now consider this instantiations:
Construct three distinct pieces of data that belong to this collection.
Answer
StringThis is a data structure containing a number and a list of strings, where the number is the same as (length List-of-Strings)
eg (make-bucket 2 (list "The" "cat"))
eg (make-bucket 4 (list "The" "cat" "in" "the" "hat"))
IR
Assuming that 'IR' in this case refers back to the Inventory Records discussed previously, then this is a data structure containing a number and a list of Inventory Records, where the number is the same as (length List-of-IR)
eg (make-bucket 2 (list (make-ir "widget" 3) (make-ir "gadget" 4)))
eg (make-bucket 3 (list (make-ir "widget" 3)
(make-ir "gadget" 4)
(make-ir "midget" 9)))
Posn
This is a data structure containing a number and a list of Posns, where the number is the same as (length List-of-Posn)
eg (make-bucket 2 (list (make-posn 1 2) (make-posn 4 2)))
eg (make-bucket 3 (list (make-posn 1 2) (make-posn 4 2) (make-posn 9 1)))
[Bucket [List-of [List-of String]]]
Construct three distinct pieces of data that belong to this collection.
;
We construct 3 lists here. Note that the number (1 2 and 3) refers to the number of Lists-of-strings we have, *not* the number of strings in the Lists-of-strings.
(make-bucket 1 (list (list "this" "is" "a" "string")))
(make-bucket 2 (list (list "this" "is" "a" "string")
(list "this" "is" "another" "string")))
(make-bucket 3 (list (list "this" "is" "a" "string")
(list "this" "is" "another" "string")
(list "this" "is" "a" "third" "string")
))
No comments:
Post a Comment