Exercise 192: Here are two strange but similar data definitions:
|
|
Both data definitions exploit this structure type definition:
Both define nested forms of data’ one is about numbers and the other about strings. Make examples for both. Abstract over the two. Then instantiate the abstract definition to get back the originals.
Answer
A Nested String and Neste Number are data constructs that contain further datastructures of the same time.
This seems very similar to a list, but it's not quite the same...
; Nested-string examples - a simple example and then a nested example
(make-layer "cat")
(make-layer (make-layer "bob"))
; Nested-number examples - a simple example and then a nested example
(make-layer 1)
(make-layer (make-layer 2))
Abstraction of the two - this question seems a little strangely worded. I think it means to define an astract function definition.
; A [Nested ITEM] is one of:
; – empty
; – (make-layer [Nested ITEM])
Instantiate to get back to the originals. This part seems to simple - probably I am overlooking something here. This is just reversing our abstraction for each type
; String
; A Nested-string is one of:
; – empty
; – (make-layer [Nested-string])
; Number
; A Nested-number is one of:
; – empty
; – (make-layer [Nested-number])
No comments:
Post a Comment