Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!ptsfa!lll-tis!lll-lcc!rutgers!sri-unix!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.lisp Subject: Re: A CL iteration macro, "while". Summary: already published Keywords: LOOP WHILE UNTIL ITERATION MACROS Message-ID: <544@cresswell.quintus.UUCP> Date: 17 Jan 88 05:09:13 GMT References: <13639@beta.UUCP> <3503@whuts.UUCP> <464@dcl-csvax.comp.lancs.ac.uk> Organization: Quintus Computer Systems, Mountain View, CA Lines: 53 In article <464@dcl-csvax.comp.lancs.ac.uk>, simon@comp.lancs.ac.uk (Simon Brooke) writes: > In article <3503@whuts.UUCP> davel@whuts.UUCP (David Loewenstern) writes: > Yes, that's nice; but there's a nicer. How about this, which is Arthur > Norman's loop macro: > > (loop ~exprs~ > (until ) > ~exprs~ > (while ) > ~exprs~ > ) > It appears in Acornsoft's Lisp for the BBC Micro and their more recent > Lisp for the new Acorn RISC machine (Archimedes); so you lot west of the A very similar construct was published in BIT (I think) in the early 70s. That construct had (REPEAT . forms) where among the forms you could have WHILE expr - if expr => NIL, returns NIL from REPEAT UNTIL expr - if expr => non-NIL, returns it from REPEAT Note that there are no parens around WHILE or UNTIL. It wasn't that hard to expand: (defmacro REPEAT (&rest forms) `(PROG () L ,@(expand-REPEAT-body forms))) (defun expand-REPEAT-body (forms) (cond ((null forms) `((GO L))) ((eq (car forms) 'WHILE) `((COND ((NOT ,(cadr forms)) (RETURN NIL))) ,@(expand-REPEAT-body (cddr forms)) )) ((eq (car forms) 'UNTIL) `((LET ((X ,(cadr forms))) (COND (X (RETURN X))) ,@(expand-REPEAT-body (cddr forms)) )) ) (t `(,(car forms) ,@(expand-REPEAT-body (cdr forms)) )) )) [This has been tested in Xlisp 1.6] The original article was actually proposing the construct for general use, but chose Lisp as a handy specification language. The trouble with all of this is that we each end up with our own language. In an Interlisp project, I had my own (while ...) (until ...) (when ...) and (unless ...) macros. This was ok until we added another programmer, who didn't want to load all of my environment just so that he could use the parts he was supposed to be working on. (There were other problems.) Let's face it, none of the macros various people like is enough of an improvement on FOR or loop to pay for the confusion in multi-programmer projects. (LETS would be. Is there a PD version?)