diff options
author | Tomas Volf <~@wolfsden.cz> | 2024-05-19 00:47:07 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2024-10-26 19:45:11 +0200 |
commit | 1c093d8bc4b74bd7392f1520c2135d8ba40a2735 (patch) | |
tree | aaf05d0957a423a0db4fbe3afddfbc0d5124c269 | |
parent | a0368a61204e02b892069b5a7937b0c3900215ae (diff) | |
download | guile-1c093d8bc4b74bd7392f1520c2135d8ba40a2735.tar.gz |
doc: Recommend alist-copy instead of list-copy.
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 <ludo@gnu.org>
-rw-r--r-- | doc/ref/api-data.texi | 2 |
1 files changed, 1 insertions, 1 deletions
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 |