Created
September 4, 2016 05:41
-
-
Save lispm/abe13010c38caa7946e3a8cd1540e385 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun circular-mapc (function list) | |
(loop for fast = list then (cddr fast) | |
for slow = list then (cdr slow) | |
do | |
(funcall function (car slow)) | |
(when (eq (cddr fast) (cdr slow)) | |
(return-from circular-mapc nil)))) | |
(defun circular (items) | |
(check-type items cons) | |
(setf (cdr (last items)) items) | |
items) | |
(defun circular-member-p (item list) | |
(circular-mapc (lambda (e) | |
(when (eql item e) | |
(return-from circular-member t))) | |
list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment