This is a homework question, but I really just need some hints, that's all.
Basically, I need to create this function flat
that's supposed to re-contract a new list from the input list (but here, the input list can have a nested list inside):
ex. flat of (A (B (C) D) A) is (A B C D A)
My algorithm is the following, not sure if it's correct:
- Check if the list is empty: if not, go on; if yes, done -- return the empty list
- If the list has length 1, done -- return the list
- If list has length more than 1, what do I do now? (I can use
car
andcdr
to extract the list, but in either case, how can I make it recursively extract the list to the end, and I'm thinking use append to re-construct the list after.)
Any help/hints would be appreciated.