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 following code which I think looks cleaner. I just don't understand the line:
((atom tree)(list tree))
I understand what each of them do individually, 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. But I still don't feel like I fully understand the code.
(defun flatten (tree)
(cond ((null tree)
nil
)
((atom tree)(list tree))
(t
(loop for a in tree appending (flatten a)))))
An explanation would terrific if anyone could spare the time? Thanks!