Question: Define function (myreverse lst) in Scheme language (DrRacket) that takes a list lst as the only one argument and returns the reversed list of lst.
Define function (myreverse lst) in Scheme language (DrRacket) that takes a list lst as the only one argument and returns the reversed list of lst.
a. (10 points) No restriction in the program.
This is the code for a), but how would it be with the restrictions in b?
define (myreverse lst) ;function defninition
(if (null? lst)
lst
(append (reverse (cdr lst)) (list (car lst)))))
(myreverse ' (1 2 3)) ;function call to test
b. (10 points) You are only allowed to use letrec, cons, car, and cdr in your program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
