nes*_*een 2 lisp common-lisp palindrome
我想通过比较第一个元素和最后一个元素来测试这个列表是否是回文,第二个元素与最后一个元素之前比较等等
(setq l '(1 5 7 8 8 7 5 1))
(defun f (l)
(cond ((null l) 0)
((atom l) l)
(if (equal (car l) (car(cdr l))))
Run Code Online (Sandbox Code Playgroud)
这种比较方式有没有理由?如果没有,使用该reverse功能会更容易:
(defun palindrome-p (l)
(equal l (reverse l)))
Run Code Online (Sandbox Code Playgroud)