conditional loop

Discussion of Common Lisp
Post Reply
mparsa
Posts: 26
Joined: Mon Jun 25, 2012 6:15 am

conditional loop

Post by mparsa » Wed Jun 27, 2012 7:41 am

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.

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: conditional loop

Post by Goheeca » Wed Jun 27, 2012 9:03 am

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.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

pjstirling
Posts: 166
Joined: Sun Nov 28, 2010 4:21 pm

Re: conditional loop

Post by pjstirling » Thu Jun 28, 2012 3:24 am

Code: Select all

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

Post Reply