conditional loop

Discussion of Common Lisp

conditional loop

Postby 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.
mparsa
 
Posts: 26
Joined: Mon Jun 25, 2012 6:15 am

Re: conditional loop

Postby 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-for-black-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).
User avatar
Goheeca
 
Posts: 165
Joined: Thu May 10, 2012 12:54 pm

Re: conditional loop

Postby 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))
pjstirling
 
Posts: 63
Joined: Sun Nov 28, 2010 4:21 pm


Return to Common Lisp

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron