Message from discussion
Collecting/LOOP (was Re: Please help)
From: stic...@Pacific.ai.sri.com (Mark Stickel)
Subject: Re: Collecting/LOOP (was Re: Please help)
Date: 1999/04/08
Message-ID: <wnzp4iwfwx.fsf@Pacific.AI.SRI.COM>#1/1
X-Deja-AN: 464313104
References: <01be763a$7e1f16e0$LocalHost@ppnorn.atlant.ru> <ucmK2.3900$L66.4085@news.rdc1.bc.wave.home.com> <lwoglh997m.fsf@copernico.parades.rm.cnr.it> <87iubpj1ra.fsf@foobar.orion.no> <7ddg3k$dpu$1@nnrp1.dejanews.com> <86677pmt0b.fsf@g.pet.cam.ac.uk> <7dgrsv$dt3$1@nnrp1.dejanews.com> <sfwzp4zn6la.fsf@world.std.com> <7ecg38$e26$1@nnrp1.dejanews.com> <m3d81ha5l4.fsf@localhost.localdomain> <370BB3F2.A36081F9@computer.org> <nkju2ur2yxd.fsf@tfeb.org> <slrn7gq76o.iej.Webmaster@meta.Tesserae.COM> <370D465E.6F9536E3@IntelliMarket.Com>
Organization: SRI International, Menlo Park, CA
Newsgroups: comp.lang.lisp
I also have reservations about the loop syntax
and want a convenient way of collecting values
other than loop or the push/nreverse idiom.
For example, what I would like to say is
(let ((primes nil))
(dotimes (i 100)
(when (primep i)
(collect i primes)))
primes)
where collect is a constant-time operation that
collects values in the proper order.
You can write a collect macro with constant-time
proper order behavior that uses two places to
store results--the collected list and its tail.
The name of the second place can be computed at macro
expansion time from the first.
In the example above, collect would use
primes to store the list and primes-last to
store its tail. Now the biggest flaw in the
approach is that the user must declare the second
place. The code is exactly as above,
except for the added declaration of primes-last
(let ((primes nil) primes-last)
(dotimes (i 100)
(when (primep i)
(collect i primes)))
primes)
Not perfect, but close.