I can’t seem to figure out how to write this function. What I am trying to write is a function expand that takes a list lst as a parameter of the form '(a (2 b) (3 c)) and is evaluated to '(a b b c c c)
I can’t seem to figure out how to write this function. What I am
Share
This looks like homework, so I’m not giving you a straight answer. Instead, I’ll give you some pointers in the right direction. The most useful hint, is that you should split the problem in two procedures, one for processing the “outer” list and the other for generating the repetitions encoded in the inner sublists.
Notice that both procedures are mutually recursive (e.g., they call each other). The
expandprocedure recurs over the list, whereas therepeatprocedure recurs over the number of repetitions. This is the general structure of the proposed solution, fill-in the blanks: