Showing posts with label Lisp. Show all posts
Showing posts with label Lisp. Show all posts

Thursday, March 31, 2011

Shift list elements in Lisp

In continuation to the post "Shift list elements in Prolog". Implementation in Lisp:
(defun lshift (l) (append (cdr l) (list (car l))))
(defun rshift (l)
  (cond
    ((null l) nil)
    ((null (cdr l)) l)
    (t
      ((lambda (r) (cons (car r) (cons (car l) (cdr r))))
        (rshift (cdr l)))
    )
  )
)