unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Tomas Volf <~@wolfsden.cz>
To: 71047@debbugs.gnu.org
Cc: Tomas Volf <~@wolfsden.cz>
Subject: bug#71047: [PATCH] doc: Recommend alist-copy instead of list-copy.
Date: Sun, 19 May 2024 00:47:07 +0200	[thread overview]
Message-ID: <20240518224707.28233-1-~@wolfsden.cz> (raw)

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






                 reply	other threads:[~2024-05-18 22:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='20240518224707.28233-1-~@wolfsden.cz' \
    --to=~@wolfsden.cz \
    --cc=71047@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).