This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: bug in append!


On Mon, 18 Oct 1999, Roland Orre wrote:

> Marius Vollmer <mvo@zagadka.ping.de> wrote:
> > Roland Orre <orre@nada.kth.se> writes:
> > 
> > > When you develop things it is always a good rule to use e.g
> > > (set! a (append a '(b)))
> > > and when everything works you can change some of the append to append!
> > > to possibly speed up things.
> 
> > I don't think that this is a good advice.  `append!' and `append'
> > behave very differently when it comes to sharing of cons cells and
> > this becomes very important when you modify your lists later (with
> > `set-car!' or `set-cdr!', for example).  Thus, replacing `append' with
> > `append!' is not merely a performance hack, it affects the behaviour
> > of your program in a fundamental way.
> 
> OK, I agree, it all depends on what you want to do and your programming
> style. The same type of problem can be solved in many different ways.
> There are the purists functional style programmers and the more imperative
> ones (scheme is wonderful, suits everyone). For my own, when I'm writing
> a new routine I usually design it from the beginning to use append! and
> a lot of set-car! and set-cdr! especially if it is an algorithm that I
> intend to move to C later on because then it's much easier to translate it.
> On the other hand, if you use append! when you not need to from the start,
> it may be (my experience) easy to obtain hard to find errors due to the
> side effects.

A compiler should be able to figure out possible side-effects and then
decide whether or not to replace append by append! as a performance
optimization.  The question is whether such optimizations could be made a
(configurable) part of guile?

Are such optimizations done in hobbit, for example?  Then it would be easy
to integrate them into guile.

Best regards,
Dirk Herrmann


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]