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!


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.

	Best regards
	Roland

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