[plt-scheme] append!?

From: hufflen at lifc.univ-fcomte.fr (hufflen at lifc.univ-fcomte.fr)
Date: Sat Oct 20 17:27:06 EDT 2007

>
> (append! L1 L2) mutates the first cdr field in L1 that contains NULL
> so that it points to L2.
> It then returns L1. If L1 is NULL, it returns L2.
>
> You may wish to think of the overall effect of appending L2 at the
> end of L1, but note that
> append! is an imperative procedure and affects all pointers to L1

   Personally, I think that the best approach of (append! L1 L2) is:
   -it results in the concatenation of L1 and L2,
   -L1 and/or L2 may be physically changed, but "may" should read as "may
or may not". In fact:
(define (append! L1 L2)
  (append L1 L2))
is a correct implementation: append! is allowed to be destructive but does
not have to. So, catching the result of (append! x y) in x is:(set! x
(append! x y))

J.-M.




Posted on the users mailing list.