GNU bug report logs - #59595
[PATCH 1/3] Add examples and incomplete wordings.

Previous Next

Package: guile;

Reported by: Yuval Langer <yuvallangerontheroad <at> gmail.com>

Date: Sat, 26 Nov 2022 04:11:03 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 59595 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#59595; Package guile. (Sat, 26 Nov 2022 04:11:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Yuval Langer <yuvallangerontheroad <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sat, 26 Nov 2022 04:11:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Yuval Langer <yuvallangerontheroad <at> gmail.com>
To: bug-guile <at> gnu.org
Cc: Yuval Langer <yuvallangerontheroad <at> gmail.com>
Subject: [PATCH 1/3] Add examples and incomplete wordings.
Date: Fri, 25 Nov 2022 22:14:34 +0200
---
 doc/ref/api-data.texi | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index 8658b9785..8c18b4d40 100644
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -4767,7 +4767,7 @@ It also allows further properties to use the same symbols among their
 possible values without becoming ambiguous:
 
 @lisp
-(define car1-properties '((colour . red)
+(define car2-properties '((colour . red)
                           (transmission . manual)
                           (fuel . unleaded)
                           (steering . power-assisted)
@@ -4793,6 +4793,37 @@ extract or change individual pieces of information:
  (locking . manual)))
 @end lisp
 
+Notice that if we try the same @code{assq-set!} call with
+@code{car2-properties}, we get an exception:
+
+@lisp
+(assq-set! car2-properties 'seat-colour 'black)
+@end lisp
+
+This is due to the fact that literal alists are immutable. If you want
+to mutate an alist, you must define it using the @code{acons}
+constructor:
+
+@lisp
+(define car3-properties (acons 'colour 'red
+                        (acons 'transmission 'manual
+                        (acons 'fuel 'unleaded
+                        (acons 'steering 'power-assisted
+                        (acons 'seat-colour 'red
+                        (acons 'locking 'manual '())))))))
+
+(assq-ref car3-properties 'seat-colour) @result{} red
+(assq-set! car3-properties 'seat-colour 'black)
+@result{}
+((colour . red)
+ (transmission . manual)
+ (fuel . unleaded)
+ (steering . power-assisted)
+ (seat-colour . black)
+ (locking . manual)))
+(assq-ref car3-properties 'seat-colour) @result{} black
+@end lisp
+
 Hash tables also have keys, and exactly the same arguments apply to the
 use of symbols in hash tables as in association lists.  The hash value
 that Guile uses to decide where to add a symbol-keyed entry to a hash
-- 
2.30.2





This bug report was last modified 2 years and 2 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.