Common Lisp:判断列表是否包含嵌套列表的谓词?

Common Lisp: A predicate to tell if a list contains a nested list?

我需要一个谓词 returns 如果列表有子列表则为真,否则为假。

我写了一个函数来实现它(下)。我想知道这样的谓词是否已经存在?

(defun hasSublistp (lst)
    (cond ((null lst) nil)
          ((listp (first lst)) t)
          (t (hasSublistp (rest lst)))))

这应该可以解决问题:

? (some #'listp '(1 2 3 4 5))
NIL
? (some #'listp '(1 2 (3 4) 4 5))
T
? (some #'listp '(1 2 (3 4) (4 7) 5))
T

我不认为 正是 用于此目的的函数,但是:

(some #'listp my-list)

您可以在 hyperspec 中找到有关高阶函数 some 的更多信息。