[plt-scheme] append!?

From: Will Farr (farr at mit.edu)
Date: Sun Oct 21 14:32:38 EDT 2007


On 10/21/07, Majorinc, Kazimir <kazimir at chem.pmf.hr> 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 the subsequent posters may have overlooked this point: append
*does not need to copy its last argument*.  A quick (inefficient)
definition of append:

(define append
    ((l1 l2)
     (if (null? l1)
         (cons (car l1) (append (cdr l1) l2))))
    ((l1 l2 . ls)
     (apply append (append l1 l2) ls))))

Note the the list l2 is not copied.  So, you don't have to worry about
using append with a long final argument; instead you should worry
about using append with long first arguments :).


Posted on the users mailing list.