;;; Best viewed with a REPL-enabled editor. (macroexpand '(tails-do* (((x accum-list tail t)) (i 1 (1+ i)) (flipper t (not flipper))) ((= i 10) accum-list) (setq x (when flipper i)))) (tails-do* (((x accum-list tail ((not (= x 3)) 3))) (i 1 (1+ i)) (flipper t (not flipper))) ((= i 10) accum-list) (if flipper (setq x i))) (macroexpand '(tails-do* (((x accum-list tail)) (y 4)) ((= y 10) (rplacd tail (list 4)) accum-list) (setq x (incf y)))) (defparameter tlis '(1 2 3 4)) ;;; Someday I'll use this? (defparameter lenlim (length tlis)) ;;; 0 - (v nil nil) ;;; Should give an error of some sort. #+(or) (tails-do* (((x)) (i 5 (1+ i))) ((= i 10) tlis) (setq x i)) ;;; 1 - (v nil ta) ;;; Treat /tail/ as the tail ;;; from a list that already exists, ;;; build onto it accordingly. (let ((tail (last tlis))) (tails-do* (((x nil tail)) (i 5 (1+ i))) ((> i 10) tlis) (setq x i))) ;;; 2 - (v nil (ta tadef)) ;;; Again, treat tail as having a home ;;; already, but let it initialize in ;;; the loop declaration. (tails-do* (((x nil (tail (last tlis)))) (i 5 (1+ i))) ((= i 10) tlis) (setq x i)) ;;; 3 - (v a nil) ;;; Create a list /lis/ and accumulate ;;; into it. (tails-do* (((x lis)) (i 5 (1+ i))) ((= i 10) (append '(1 2 3 4) lis)) (setq x i)) ;;; 4 - (v a ta) ;;; Create a list /lis/ and accumulate ;;; into it using the tail /tail/. (tails-do* (((x lis tail)) (i 1 (1+ i))) ((= i 10) lis) (setq x i)) ;;; 5 - (v a (ta tadef)) ;;; Let /tail/ be initialized in the loop ;;; delaration. Whatever it is, let /lis/ ;;; accumulate the newly added elements ;;; as well. (tails-do* (((x lis (tail (last tlis)))) (i 5 (1+ i))) ((= i 10) (append '(1 2 3 4) lis)) (setq x i)) ;;; 6 - (v (a adef) nil) ;;; Have /lis/ initialized as an existing ;;; list. Build onto it accordingly. (tails-do* (((x (lis tlis))) (i 5 (1+ i))) ((= i 10) lis) (setq x i)) ;;; 7 - (v (a adef) ta) ;;; Have /lis/ not be built from scratch. ;;; Build onto it with /tail/ as its tail. (tails-do* (((x (lis tlis) tail)) (i 5 (1+ i))) ((= i 10) lis) (setq x i)) ;;; 8 - (v (a adef) (ta tadef)) ;;; The best action here is to leave /lis/ alone ;;; and hope the caller defined it with a relation ;;; to /tail/. ;;; ;;; Otherwise, their style sucks. (tails-do* (((x (lis tlis) (tail (last tlis)))) (i 5 (1+ i))) ((= i 10) lis) (setq x i))