我正在尝试编写一个确定列表深度的函数。因此对于
等等。
这是我到目前为止编写的内容,它仅适用于线性列表(深度= 1)和深度为2的列表。
我认为我已经接近正确的解决方案,但我觉得自己缺少一些东西。
(defun detlen (lst count)
(
cond
((null lst) count)
((LISTP (car lst)) (setq count (+ count 1)) (detlen (cdr lst) count))
(t (detlen (cdr lst) count))
)
)
Run Code Online (Sandbox Code Playgroud)