I could not find a similar problem here, but I’m trying to write a program in scheme for a class so hints would be very well appreciated! I’m basically confused as to how to implement this but here is an example on how it’s supposed to work. (index 5) is supposed to return the list (1 2 3 4 5). I have a couple of ideas, could they work?
-
I make the argument a global variable which I increment each time I call the function recursively. the problem I’ve had with this so far is that using set! returns a list but the output would look something like this (#value #value….)
-
program a simple recursive function that gives the list (5 4 3 2 1) and then reverse it, but would I be able to do that?
I’d go with solution 2 as it is by far the cleanest, least complicated option. You just need to figure out the recursion. Hint: the base case is reached at
(index 0), which should return the empty list. Reversing afterward can be done by putting actual recursion in a helper function:(Or use a named-
letloop.)