From 1c093d8bc4b74bd7392f1520c2135d8ba40a2735 Mon Sep 17 00:00:00 2001 From: Tomas Volf <~@wolfsden.cz> Date: Sun, 19 May 2024 00:47:07 +0200 Subject: [PATCH] doc: Recommend alist-copy instead of list-copy. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current recommendation of `list-copy' is not right and does not lead to preserving the original list: scheme@(guile-user)> (define x (list (cons 'a 1) (cons 'b 2))) scheme@(guile-user)> (define y (list-copy x)) scheme@(guile-user)> (assq-set! y 'b 3) $1 = ((a . 1) (b . 3)) scheme@(guile-user)> x $2 = ((a . 1) (b . 3)) Correct approach seems to be use `alist-copy' from SRFI-1 leading to the expected behavior of: scheme@(guile-user)> ,use (srfi srfi-1) scheme@(guile-user)> (define x (list (cons 'a 1) (cons 'b 2))) scheme@(guile-user)> (define y (alist-copy x)) scheme@(guile-user)> (assq-set! y 'b 3) $1 = ((a . 1) (b . 3)) scheme@(guile-user)> x $2 = ((a . 1) (b . 2)) * doc/ref/api-data.texi (Adding or Setting Alist Entries): Recommend `alist-copy'. Signed-off-by: Ludovic Courtès --- doc/ref/api-data.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi index ae65457df..53924db01 100644 --- a/doc/ref/api-data.texi +++ b/doc/ref/api-data.texi @@ -9510,7 +9510,7 @@ difference to you. If you need to keep the old value of an association list in a form independent from the list that results from modification by @code{acons}, @code{assq-set!}, @code{assv-set!} or @code{assoc-set!}, -use @code{list-copy} to copy the old association list before modifying +use @code{alist-copy} to copy the old association list before modifying it. @rnindex acons