complier optimization for DO returning REVERSE, WAS: Re: newbie exploring better ways



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. While it could do
this, do any compilers actually do that?

I understand of course, that LOOP could frequently be used to avoid
the second iteration, but since the results are effectively
isomorphic, it be nice if the compiler would "do what I mean" and
build the more efficient version whenever possible, allowing the
programmer to always write what's easiest to code/maintain/understand
for the situation.
.



Relevant Pages

  • Re: Reverse strings
    ... Your prototype for reverse says that the parameter is of type ... This will be automatically converted by the compiler to ... type char(*)[SIZE], that is pointer to array of SIZE char. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: complier optimization for DO returning REVERSE, WAS: Re: newbie exploring better ways
    ... but the disadvantage of the extra traversal for the REVERSE ... just out of curiosity (and possibly in bad form for replying to my own ... it strikes me that a clever compiler could unroll that, ... Well, first of all, the compiler would have to have some way of making ...
    (comp.lang.lisp)
  • Re: Is it a good thing that program mix C and C++?
    ... You can call C routines from C++, but not the reverse. ... The C++ compiler does various unspeakable things to ... Since the C++ object code uses those adorned names, ...
    (comp.lang.c)
  • Re: Is it a good thing that program mix C and C++?
    ... You can call C routines from C++, but not the reverse. ... The C++ compiler does various unspeakable things to ... the function names in order to handle overloading, ...
    (comp.lang.c)