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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!