Re: complier optimization for DO returning REVERSE, WAS: Re: newbie exploring better ways
- From: tar@xxxxxxxxxxxxx (Thomas A. Russ)
- Date: 30 Jan 2008 12:44:47 -0800
K Livingston <kevinlivingston.public@xxxxxxxxx> writes:
On Jan 30, 1:39 am, K Livingston <kevinlivingston.pub...@xxxxxxxxx>
wrote:
a DO with a REVERSE at the end has no side effects,
but the disadvantage of the extra traversal for the REVERSE
just out of curiosity (and possibly in bad form for replying to my own
comment), it seems that a reasonably common form is
(do ((results nil (cons <something> results))
...)
(( ... ) (reverse results)))
it strikes me that a clever compiler could unroll that, and not
require the second traversal and just build up results in reverse, as
it would while performing a MAPCAR or the like.
Well, first of all, the compiler would have to have some way of making
sure that there were no side effects contained in the ... or (even more
difficult), prove to itself that any side effects don't affect the
computation of the results.
For a simple example that would persumably give the compiler fits trying
to figure out:
(let ((counter 0)
(limit 10))
(do ((results nil (cons (incf counter) results)))
((>= counter limit) (reverse results))))
While it could do
this, do any compilers actually do that?
I doubt it. While unrolling a loop may be a standard compiler trick,
reversing the direction of loop traversal seems a bit much.
--
Thomas A. Russ, USC/Information Sciences Institute
.
- References:
- newbie exploring better ways
- From: vijay
- Re: newbie exploring better ways
- From: Griff
- Re: newbie exploring better ways
- From: Kent M Pitman
- Re: newbie exploring better ways
- From: K Livingston
- complier optimization for DO returning REVERSE, WAS: Re: newbie exploring better ways
- From: K Livingston
- newbie exploring better ways
- Prev by Date: Re: newbie exploring better ways
- Next by Date: Re: Paul Graham's Arc is released today... what is the long term impact?
- Previous by thread: complier optimization for DO returning REVERSE, WAS: Re: newbie exploring better ways
- Next by thread: Re: newbie exploring better ways
- Index(es):
Relevant Pages
|