Let a promise list be a promise that contains either empty, or a pair whose left element is the head of
the promise list, and whose right element is the tail of the promise list, which is therefore a promise
list. The goal of this exercise is to develop a library for manipulating promise lists. Note that function
(promise? p) returns #t if, and only if value p is a promise, otherwise it returns #f.
(a) Define variable p:empty that is bound to the empty promise list.
(b) Implement function (p:empty? l) that returns #t if, and only if, variable l is a promise to a list.
Note that each promise is its unique object, so comparison always fails. For instance,
(equal? (delay 1) (delay 1)) evaluates to #f. Thus, simply l against promise p:empty is
incorrect.
(c) Manually graded. Explain if it is possible to implement a function (p:cons x l) that constructs
a new promise list such that x is the head of the resulting promise list, l is the tail of the promise
list, and x is not evaluated. If you answered that it is possible, then implement (p:cons x l) and
write a test-case that illustrates its usage. If you answered that it is impossible, then explain how
to encode such a function. Your answer must be written as a comment in the solution file that you
submit.
(d) Implement function (p:first l) that obtains the head of a promise list.
(e) Implement function (p:rest l) takes a promise list and returns the tail of that promise list.
(f) Implement function (p:append l r) that concatenates two promise lists l and r. Recall the
implementation of append in class. Feel free to use the non-tail recursive version.
The post Define variable p:empty that is bound to empty promise list appeared first on My Assignment Online.