I was struggling with flattening a tree structure. I was doing it recursively by comparing each atomic symbol to the rest in the tree but, a friend of mine suggested the followi
I also know that the loop below takes a list or it causes an error, which I suspect has a lot to due with the reason we're turning the symbol into a list if atom returns true.
Spot on. The postcondition of flatten
is that its result is always a flat list (not "a flat list or an atom"), so that the recursive calls need only handle one data type.