Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!das-news.harvard.edu!news2.near.net!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!EU.net!uknet!festival!edcogsci!jeff
From: jeff@aiai.ed.ac.uk (Jeff Dalton)
Subject: Re: Looping constructs (was: Comparison: Beta - Lisp)
Message-ID: <CwsroH.BGI@cogsci.ed.ac.uk>
Sender: usenet@cogsci.ed.ac.uk (C News Software)
Nntp-Posting-Host: bute.aiai.ed.ac.uk
Organization: AIAI, University of Edinburgh, Scotland
References: <35cqdb$4k4@spool.cs.wisc.edu> <sooRsc1w165w@sytex.com> <CwJuu7.3un@rheged.dircon.co.uk>
Date: Tue, 27 Sep 1994 16:41:05 GMT
Lines: 42

In article <CwJuu7.3un@rheged.dircon.co.uk> simon@rheged.dircon.co.uk (Simon Brooke) writes:

>Cambridge LisP has the beautiful construct
>
>	(loop 
>		forms 
>		(until <condition> value) 
>		forms
>		(while <condition> value)
>		forms)

In Common Lisp, continue to use loop but replace 

    (until <condition> value) 
by  (when <condition> (return value))

and 

    (while <condition> value) 
by  (unless <condition> (return value))

"Named let" is also rather elegant.  I use:

;;; LABEL defines a "named LET" that can be called as a local function.
;;;
;;; (LABEL fname ((var init) ...) form ...)
;;;   ==> (LABELS ((fname (var ...) form ...))
;;;         (fname init ...))

(defmacro label (name init-specs &body forms)
  `(labels ((,name ,(mapcar #'car init-specs)
              ,@forms))
     (,name ,@(mapcar #'cadr init-specs))))

E.g. to print 0 .. 9:

(label repeat ((i 0))
  (when (< i 10)
    (print i)
    (repeat (1+ i))))

-- jeff
