unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#71047: [PATCH] doc: Recommend alist-copy instead of list-copy.
@ 2024-05-18 22:47 Tomas Volf
  2024-10-26 17:33 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: Tomas Volf @ 2024-05-18 22:47 UTC (permalink / raw)
  To: 71047; +Cc: Tomas Volf

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'.
---
 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 3b9933d97..81552dec3 100644
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -9509,7 +9509,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.
 
 @deffn {Scheme Procedure} acons key value alist
-- 
2.41.0






^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#71047: [PATCH] doc: Recommend alist-copy instead of list-copy.
  2024-05-18 22:47 bug#71047: [PATCH] doc: Recommend alist-copy instead of list-copy Tomas Volf
@ 2024-10-26 17:33 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2024-10-26 17:33 UTC (permalink / raw)
  To: Tomas Volf; +Cc: 71047-done

Tomas Volf <~@wolfsden.cz> skribis:

> 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'.

Applied, thanks!





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-26 17:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-18 22:47 bug#71047: [PATCH] doc: Recommend alist-copy instead of list-copy Tomas Volf
2024-10-26 17:33 ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).