Page 1 of 1

conditional loop

Posted: Wed Jun 27, 2012 7:41 am
by mparsa
How we can have a conditional loop in lisp ?
I know that we can dotimes for having loop but I want to have a condition : until var is not equal to "test" continue and when it equals to "test" do not continue.

Re: conditional loop

Posted: Wed Jun 27, 2012 9:03 am
by Goheeca
Check out loop macro (http://www.unixuser.org/~euske/doc/cl/loop.html, http://www.gigamonkeys.com/book/loop-fo ... belts.html)

Solution for your issue is:

Code: Select all

(loop until condition do form)
where condition and form are code not loop keywords.

Re: conditional loop

Posted: Thu Jun 28, 2012 3:24 am
by pjstirling

Code: Select all

(defmacro until (test &body body)
  `(do ()
       (,test)
     ,@body))
;; and its companion
(defmacro while (test &body body)
  `(until (not ,test)
     ,@body))