判断回文的函数palindrome?

CL-USER> (defun palindrome? (x)
       (let ((mid (/ (length x) 2)))
         (equal (subseq x 0 (floor mid))
            (reverse (subseq x (ceiling mid))))))
PALINDROME?
CL-USER> (palindrome? "abba")
T
CL-USER> (palindrome? "abcba")
T
CL-USER>

 

注:subseq函数只会取到第二个数字参数的前面

CL-USER> (subseq "hellolleh" 0 4)
"hell"

posted @ 2013-01-04 17:59  flowjacky  阅读(436)  评论(0编辑  收藏  举报