Skip to content

Instantly share code, notes, and snippets.

@nfunato
Created October 27, 2012 19:15
Show Gist options
  • Save nfunato/3965733 to your computer and use it in GitHub Desktop.
Save nfunato/3965733 to your computer and use it in GitHub Desktop.
recons / relist / relist*
;;; 2012/10/27 @nfunato
;;; Probably I first saw them at Xerox PCL about 25 years ago.
;;; I think almost same code can be seen in many places, including CLtL2.
;;; recons / relist / relist*
(defun recons (x a d)
(destructuring-bind (xa . xd) x
(if (and (eql xa a) (eql xd d))
x
(cons a d))))
(defun relist-1 (x a d star?)
(if (null d)
(if star? a (recons x a d))
(recons x a (relist-1 (cdr x) (car d) (cdr d) star?))))
(defun relist (x &rest args)
(if (null args)
nil
(relist-1 x (car args) (cdr args) nil)))
(defun relist* (x a &rest d)
(relist-1 x a d t))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment