x.øi5yle=”border-collapse: collapse; font-family: Arial; font-size: 12px; line-height: 18px;…

x.øi5yle=”border-collapse: collapse; font-family: Arial; font-size: 12px; line-height: 18px; “>Question Details:Exercise 13. For Assignment 4, you defined the procedure reverse-list. A call to your version ofreverse-list probably resulted in the following sort of error when passed an invalid argument.

——————————-
(define combine-lists
(lambda (a b)
(if (null? a) b (combine-lists (cdr a) (cons (car a) b)))))

(define reverse-list
(lambda (ls)
(combine-lists ls '())))
———————————

> (reverse-list 3)

Error in cdr: 3 is not a pair.
> (reverse-list '(a b . c))

Error in cdr: c is not a pair.

Define reverse-list using an internally defined help procedure. Have the help procedure signal an error if the incoming argument is not a pairor empty list. Your solution should make only one pass through the list. In particular, you should not use list?, proper-list?, or the equivalent to first check if thelist is proper, since this would count as an additional pass through the list. (Of course, you may use the built-in pair? predicate.) (Naturally, you may not use thebuilt-in reverse procedure since the point of the exercise is to implement that procedure.)

Identify the error as coming from reverse-list, not from the helper, and show the original input to reverse-list in the error message, even if the error occurs someiterations into the loop.

> (reverse-list 3)

Error in reverse-list: 3 is not a proper list.
> (reverse-list '(a . b))

Error in reverse-list: (a . b) is not a proper list.
> (reverse-list '(a b . c))

Error in reverse-list: (a b . c) is not a proper list.
> (reverse-list '(should it work? this does))
(does this work? it should)

Hint: The text of this exercise tells exactly how to detect the error. MÅà.à.?Óp.p.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer