Flattening a tree structure in Lisp

前端 未结 3 1531
太阳男子
太阳男子 2021-01-28 18:59

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

3条回答
  •  有刺的猬
    2021-01-28 19:21

    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.

提交回复
热议问题