Re: writing my own version of loop



Jon Boone wrote:
I am reading through Patrick Harrison's
_Common_Lisp_&_Artificial_Intelligence_ and have just finished the
chapter on macros. One of the problems presented at the end of the
chapter involves writing a loop macro that has the following
syntax:

LOOP {form}* UNTIL test

I have come up with the following solution, but I'm not happy with
it. Does anyone else have suggestions on how to improve it?

(defmacro my-loop (&body body)
(let* ((start (gensym))
(end (gensym))
(smorf (reverse body))
(test (car smorf))
(forms (reverse (cddr smorf))))
`(tagbody
,start
,@forms
(if ,test (go ,end))
(go ,start)
,end nil)))

Ideas:
- Use last/butlast to separate the body.
- replace the 'if and 'end with a single 'unless

HTH,
Daniel
.