Subject: Re: Beyond CL?
From: rpw3@rpw3.org (Rob Warnock)
Date: Fri, 22 Jul 2005 22:44:04 -0500
Newsgroups: comp.lang.lisp
Message-ID: <a7adnQZO9_qZIHzfRVn-gw@speakeasy.net>
O-MY-GLIFE <vrotaru@seznam.cz> wrote:
+---------------
| Recently I had a feeling that I need a WHILE loop. Maybe not a lispy
| feeling but what the heck?!
| 
| (defmacro while (test &body body)
|   `(tagbody
|     start
|     (unless ,test (go end))
|     ,@body
|     (go start)
|     end))
+---------------

I was about to suggest that you make START & END be gensyms, to allow
proper nesting, then realized there's a much simpler solution:

    (defmacro while (test &body body)
      `(do () ((not ,test)) ,@body))

But in CMUCL, guess what that expands to? Surprise, surprise!  ;-}  ;-}

    > (macroexpand '(while (< x 3) (print x) (incf x)))

    (BLOCK NIL
      (LET ()
	(TAGBODY
	  (GO #:G981)
	 #:G980
	  (PRINT X)
	  (INCF X)
	  (PSETQ)
	 #:G981
	  (UNLESS (NOT (< X 3)) (GO #:G980))
	  (RETURN-FROM NIL (PROGN)))))
    T
    >


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607