From: Yuval Langer <yuvallangerontheroad@gmail.com>
To: 59595@debbugs.gnu.org
Cc: Yuval Langer <yuvallangerontheroad@gmail.com>
Subject: bug#59595: [PATCH 1/3] Add examples and incomplete wordings.
Date: Fri, 25 Nov 2022 22:14:34 +0200 [thread overview]
Message-ID: <20221125201436.35241-1-yuvallangerontheroad@gmail.com> (raw)
---
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
next reply other threads:[~2022-11-25 20:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-25 20:14 Yuval Langer [this message]
2022-11-25 20:14 ` bug#59596: [PATCH 2/3] Add an interactive session exception error message Yuval Langer
2022-11-25 20:14 ` bug#59597: [PATCH 3/3] Change order of the resulting alist - a new entry is added to the start of the alist Yuval Langer
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=20221125201436.35241-1-yuvallangerontheroad@gmail.com \
--to=yuvallangerontheroad@gmail.com \
--cc=59595@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).