Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Racket Programming Language Question .DO number c only. Answer number c only. The answer to 1.a and 1.b are as follows , it might help
Racket Programming Language Question .DO number c only.
Answer number c only. The answer to 1.a and 1.b are as follows , it might help you answer number c.
1a) (define p:empty (delay empty))
1b)define (p:empty? p) (cond[(and (promise? p)(equal? empty (force p))) #t] [else #f]))
1c) your answer
Thanks
1. (30 points) 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) (2 points) Define variable p:empty that is bound to the empty promise list. (check-equal? empty (force p:empty)) (b) (3 points) Implement function (p: empty? 1) that returns #t if and only if variable 1 is a promise to a list. Note that each promise is its unique object, so comparison always fails. Forin stance, (equal? (delay 1) (delay 1)) evaluates to #f. Thus, simply 1 against promise p: empty is incorrect. check-true (p:empty? p:empty)) (check-false (p:empty? 10)) (c10 points) Manually graded. Explain if it is possible to implement a function (p:cons x 1) that constructs a new promise list such that x is the head of the resulting promise list, 1 is the tail of the promise list, and x is not evaluated. If you answered that it is possible, then implement p:cons x 1) 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. 1. (30 points) 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) (2 points) Define variable p:empty that is bound to the empty promise list. (check-equal? empty (force p:empty)) (b) (3 points) Implement function (p: empty? 1) that returns #t if and only if variable 1 is a promise to a list. Note that each promise is its unique object, so comparison always fails. Forin stance, (equal? (delay 1) (delay 1)) evaluates to #f. Thus, simply 1 against promise p: empty is incorrect. check-true (p:empty? p:empty)) (check-false (p:empty? 10)) (c10 points) Manually graded. Explain if it is possible to implement a function (p:cons x 1) that constructs a new promise list such that x is the head of the resulting promise list, 1 is the tail of the promise list, and x is not evaluated. If you answered that it is possible, then implement p:cons x 1) 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 submitStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started