Created
July 24, 2010 08:12
-
-
Save kurohuku/488525 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 dotted-list-p (lst) | |
(when (consp lst) | |
(loop :for rest = (cdr lst) then (cdr rest) | |
:while (consp rest) | |
:finally (return (not (null rest)))))) | |
(defun walk-inner (sexp pre mid post) | |
(cond | |
((atom sexp) | |
(funcall mid sexp)) | |
((dotted-list-p sexp) | |
(loop | |
:for rest = sexp then (cdr rest) | |
:collect (walk (if (consp rest) (car rest) rest) pre mid post) | |
:while (consp rest))) | |
((listp sexp) | |
(mapcar | |
#'(lambda (sexp) (walk sexp pre mid post)) | |
sexp)))) | |
(defun walk (sexp pre mid post) | |
(if (and (listp sexp) (not (dotted-list-p sexp))) | |
(funcall | |
post | |
(walk-inner | |
(funcall pre sexp) | |
pre mid post)) | |
(walk-inner sexp pre mid post))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment