[plt-scheme] append!?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Oct 21 08:08:01 EDT 2007

At Sun, 21 Oct 2007 11:31:55 +0200, "Majorinc, Kazimir" wrote:
> OK, I think I understood it. I'll use append instead of append! for all 
> occasions except if the last list is significantly bigger than other 
> lists that should be appended. In that particular case, use of the 
> append instead of append! would be a sin. Is it sound policy?

I think you should never use `append!'. It's a performance hack that no
longer provides that much performance benefit (in PLT Scheme).

See also

 http://list.cs.brown.edu/pipermail/plt-scheme/2007-May/018380.html


Also, `append!' is going away in v4.0, since `cons' will create
immutable pairs, `append' will append immutable lists, and so on.

> Somehow I think that the problem is in simple initial Lisp design 
> mistake,

I'd agree: pairs should have been immutable. :)

> i.e. linked lists that start with cell (cons) instead of 
> pointer to cons (that could be nil for empty list) are good only if one 
> does not need empty list at all.

I think you have in mind a mutable-container abstraction, such as
Java's "LinkedList". But that kind of container is different from a
Scheme "list".

And that's why `cons' will create immutable pairs in v4.0: to avoid
getting anything like mutable-container behavior where that's not
wanted (which is most of the places where you use lists in Scheme). A
nice consequence that `append!' goes away, which eliminates one common
confusion about mutation in Scheme.

Matthew



Posted on the users mailing list.