[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: another simple defmacro question

William James

8/13/2015 12:40:00 PM

Thomas A. Russ wrote:

> Not at all connected with your original problem, but you can
> exploit the full power of LOOP to greatly simplify this part
> of the code:
>
> > (let ((stringlist)
> > (tmpstr))
> > (with-open-file (infile fname :direction :input)
> > (loop
> > (setq tmpstr (read-line infile nil nil))
> > (unless tmpstr
> > (return))
> > (push tmpstr stringlist)
> > ))
> > (setq stringlist (nreverse stringlist))
> > stringlist
> > ))
>
> It can be transformed into:
>
> (with-open-file (infile fname :direction :input)
> (loop for tmpstr = (read-line infile nil nil)
> while tmpstr
> collect tmpstr))

Gauche Scheme:

(with-input-from-file fname
(cut generator-map identity read-line))

--
Sahlin [stressed] that her compatriots must accept that the new Sweden is
multi-cultural.... "Like it or not, this is the new Sweden."
fjordman.blogspot.ca/2005/05/is-swedish-democracy-collapsing.html