Palindrome in Lisp

Here’s my version of palindrome for lisp problems 99 no 06 found here


(defun last1 (lst)
  (car (last lst)))

(defun palin1 (lst)
  (if (equal nil lst)
  t
  (let ((start (first lst)) (finish (last1 lst)))
    (if (equal start finish)
    (palin1 (rest (butlast lst)))
    nil))))
About these ads

5 thoughts on “Palindrome in Lisp

  1. an iterative approach

    (defun make-palindrome(list)
    (if (= (length list) 1)
    list
    (dotimes (count (length list) list)
    (setf list (append list (list (nth (- (length list) (+ count (+ count 1))) list))))
    ))
    )

  2. A solution using mapcar and reduce

    (defun is-palindrome (lst)
    (reduce #’(lambda (x y) (if (and x y) t nil))
    (mapcar #’eql lst (reverse lst))))

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s