Re: writing my own version of loop
- From: D Herring <dherring@xxxxxxxxxxxxxxxxxxx>
- Date: Sun, 15 Jul 2007 12:09:21 -0400
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
.
- References:
- writing my own version of loop
- From: Jon Boone
- writing my own version of loop
- Prev by Date: writing my own version of loop
- Next by Date: Re: cffi hell
- Previous by thread: writing my own version of loop
- Next by thread: Re: writing my own version of loop
- Index(es):