GNU bug report logs - #32841
assoc-set fails with dot notation association list

Previous Next

Package: guile;

Reported by: "Hood, Christopher L." <Christopher.Hood <at> gtri.gatech.edu>

Date: Tue, 25 Sep 2018 20:41:02 UTC

Severity: normal

Done: lloda <lloda <at> sarc.name>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 32841 in the body.
You can then email your comments to 32841 AT debbugs.gnu.org in the normal way.

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#32841; Package guile. (Tue, 25 Sep 2018 20:41:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Hood, Christopher L." <Christopher.Hood <at> gtri.gatech.edu>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Tue, 25 Sep 2018 20:41:02 GMT) Full text and rfc822 format available.

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

From: "Hood, Christopher L." <Christopher.Hood <at> gtri.gatech.edu>
To: "bug-guile <at> gnu.org" <bug-guile <at> gnu.org>
Subject: assoc-set fails with dot notation association list
Date: Tue, 25 Sep 2018 20:33:41 +0000
[Message part 1 (text/plain, inline)]
This fails with code pulled straight out of the Guile manual example (section 6.6.20.6).

(define capitals '(("New York" . "Albany")
                   ("Oregon"   . "Salem")
                   ("Florida"  . "Miami")))

Okay, that works define to define alist capitals. Now let's try another part of the example:


(set! capitals

      (assoc-set! capitals "Florida" "Tallahassee"))

This yields the error:

ERROR: In procedure assoc-set!:
In procedure set-cdr!: Wrong type argument in position 1 (expecting mutable pair): ("Florida" . "Miami")

I've experienced this behavior with builds of both Guile 2.2.2 and Guile 2.2.4.

I'll note that if you define the alist so its initial contents are defined using a quasiquote and the cons form instead of dot notation, this error is not reached. I'm not sure if the error is valid or not, but in any case, the code that produces is listed as an valid example in the manual, so that doesn't seem right.

chris
[Message part 2 (text/html, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#32841; Package guile. (Tue, 25 Sep 2018 22:06:01 GMT) Full text and rfc822 format available.

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

From: John Cowan <cowan <at> ccil.org>
To: Christopher.Hood <at> gtri.gatech.edu
Cc: 32841 <at> debbugs.gnu.org
Subject: Re: bug#32841: assoc-set fails with dot notation association list
Date: Tue, 25 Sep 2018 18:04:59 -0400
[Message part 1 (text/plain, inline)]
The error is valid, because you are attempting to mutate a program
literal.  Scheme makes that an error, and Guile enforces it (though many
Schemes do not).

On Tue, Sep 25, 2018 at 4:41 PM Hood, Christopher L. <
Christopher.Hood <at> gtri.gatech.edu> wrote:

> This fails with code pulled straight out of the Guile manual example
> (section 6.6.20.6).
>
>
>
> (define capitals '(("New York" . "Albany")
>
>                    ("Oregon"   . "Salem")
>
>                    ("Florida"  . "Miami")))
>
>
>
> Okay, that works define to define alist capitals. Now let’s try another
> part of the example:
>
>
>
> (set! capitals
>
>       (assoc-set! capitals "Florida" "Tallahassee"))
>
>
>
> This yields the error:
>
>
>
> ERROR: In procedure assoc-set!:
>
> In procedure set-cdr!: Wrong type argument in position 1 (expecting
> mutable pair): ("Florida" . "Miami")
>
>
>
> I’ve experienced this behavior with builds of both Guile 2.2.2 and Guile
> 2.2.4.
>
>
>
> I’ll note that if you define the alist so its initial contents are defined
> using a quasiquote and the cons form instead of dot notation, this error is
> not reached. I’m not sure if the error is valid or not, but in any case,
> the code that produces is listed as an valid example in the manual, so that
> doesn’t seem right.
>
>
>
> chris
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#32841; Package guile. (Thu, 27 Sep 2018 03:03:02 GMT) Full text and rfc822 format available.

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

From: Mark H Weaver <mhw <at> netris.org>
To: "Hood\, Christopher L." <Christopher.Hood <at> gtri.gatech.edu>
Cc: 32841 <at> debbugs.gnu.org
Subject: Re: bug#32841: assoc-set fails with dot notation association list
Date: Wed, 26 Sep 2018 23:02:17 -0400
Hi Christopher,

"Hood, Christopher L." <Christopher.Hood <at> gtri.gatech.edu> writes:
> This fails with code pulled straight out of the Guile manual example
> (section 6.6.20.6).

Indeed, the example code in the manual is bad.  Thanks for bringing this
to our attention.

> (define capitals '(("New York" . "Albany")
>                    ("Oregon"   . "Salem")
>                    ("Florida"  . "Miami")))

As John correctly pointed out, it's an error to mutate a program
literal.  It's analogous to trying to modify a string literal in C.
'assoc-set!' mutates the existing list structure in some cases, and so
it cannot be used on literals such as the one above.

To initialize an alist that will be mutated, you must instead do
something like this:

  (define capitals (list (cons "New York" "Albany")
                         (cons "Oregon"   "Salem")
                         (cons "Florida"  "Miami")))

> I’ll note that if you define the alist so its initial contents are
> defined using a quasiquote and the cons form instead of dot notation,
> this error is not reached.

Yes, that accomplishes essentially the same thing, although note that
quasiquote makes an effort to use program literals for parts of the
resulting list structure, e.g.:

  `(,a ,b c d)

expands to:

  (cons a (cons b '(c d)))

which means that the first two cons cells can be mutated, but the last
two are part of an immutable program literal.

> I’m not sure if the error is valid or not, but in any case, the code
> that produces is listed as an valid example in the manual, so that
> doesn’t seem right.

Indeed, the manual needs to be fixed.  Sorry for the confusion, and
thanks again for the bug report.

     Mark




Information forwarded to bug-guile <at> gnu.org:
bug#32841; Package guile. (Thu, 27 Sep 2018 12:11:02 GMT) Full text and rfc822 format available.

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

From: John Cowan <cowan <at> ccil.org>
To: Mark H Weaver <mhw <at> netris.org>
Cc: 32841 <at> debbugs.gnu.org, Christopher.Hood <at> gtri.gatech.edu
Subject: Re: bug#32841: assoc-set fails with dot notation association list
Date: Thu, 27 Sep 2018 08:09:46 -0400
[Message part 1 (text/plain, inline)]
On Wed, Sep 26, 2018 at 11:03 PM Mark H Weaver <mhw <at> netris.org> wrote:


> To initialize an alist that will be mutated, you must instead do
> something like this:
>
>   (define capitals (list (cons "New York" "Albany")
>                          (cons "Oregon"   "Salem")
>                          (cons "Florida"  "Miami")))
>

More simply, you can wrap the literal in a call to copy-tree.  This returns
a deep copy of the literal that is fully mutable.

-- 
John Cowan          http://vrici.lojban.org/~cowan        cowan <at> ccil.org
Here lies the Christian, judge, and poet Peter,
Who broke the laws of God and man and metre.
[Message part 2 (text/html, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#32841; Package guile. (Mon, 21 Oct 2024 13:50:03 GMT) Full text and rfc822 format available.

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

From: "п" <2024110144 <at> mails.szu.edu.cn>
To: "32841" <32841 <at> debbugs.gnu.org>
Subject: Re: bug#32841: assoc-set fails with dot notation association list
Date: Mon, 21 Oct 2024 16:54:54 +0800
[Message part 1 (text/plain, inline)]
The thread and all replies were in 2018. Six years later, in 2024, Anyone opening the up-to-date online manual still sees the old bad code there! The manual is not adjusted even though previous emails had pointed the cause and solution out!
Today, the page has a valid link of&nbsp;         https://www.gnu.org/software/guile/manual/html_node/Alist-Example.html&nbsp;&nbsp;and&nbsp;still contains

         6.6.20.6&nbsp; Alist Example

Here is a longer example of how alists may be used in practice.
(define capitals '(("New York" . "Albany")                    ("Oregon"   . "Salem")                    ("Florida"  . "Miami"))) ;; What's the capital of Oregon? (assoc "Oregon" capitals)       60 ("Oregon" . "Salem") (assoc-ref capitals "Oregon")   60 "Salem" ;; We left out South Dakota. (set! capitals       (assoc-set! capitals "South Dakota" "Pierre")) capitals 60 (("South Dakota" . "Pierre")     ("New York" . "Albany")     ("Oregon" . "Salem")     ("Florida" . "Miami")) ;; And we got Florida wrong. (set! capitals       (assoc-set! capitals "Florida" "Tallahassee")) capitals 60 (("South Dakota" . "Pierre")     ("New York" . "Albany")     ("Oregon" . "Salem")     ("Florida" . "Tallahassee")) ;; After Oregon secedes, we can remove it. (set! capitals       (assoc-remove! capitals "Oregon")) capitals 60 (("South Dakota" . "Pierre")     ("New York" . "Albany")     ("Florida" . "Tallahassee"))



 

              
                                                ڴѧ                                  
                                                                    п
[Message part 2 (text/html, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#32841; Package guile. (Mon, 21 Oct 2024 20:28:01 GMT) Full text and rfc822 format available.

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

From: Tomas Volf <~@wolfsden.cz>
To: "32841" <32841 <at> debbugs.gnu.org>
Cc: .%c2.п. <2024110144 <at> mails.szu.edu.cn>
Subject: Re: bug#32841: assoc-set fails with dot notation association list
Date: Mon, 21 Oct 2024 22:26:48 +0200
".%c2.п." via "Bug reports for GUILE, GNU's Ubiquitous
Extension Language" <bug-guile <at> gnu.org> writes:

> The thread and all replies were in 2018. Six years later, in 2024, Anyone opening the up-to-date online manual still sees the old bad code there! The manual is not adjusted even though previous emails had pointed the cause and solution out!
> Today, the page has a valid link of&nbsp;         https://www.gnu.org/software/guile/manual/html_node/Alist-Example.html&nbsp;&nbsp;and&nbsp;still contains
>
>          6.6.20.6&nbsp; Alist Example
>
> Here is a longer example of how alists may be used in practice.
> (define capitals '(("New York" . "Albany")                    ("Oregon"   . "Salem")                    ("Florida"  . "Miami"))) ;; What's the capital of Oregon? (assoc "Oregon" capitals)       ⇓ ("Oregon" . "Salem") (assoc-ref capitals "Oregon")   ⇓ "Salem" ;; We left out South Dakota. (set! capitals       (assoc-set! capitals "South Dakota" "Pierre")) capitals ⇓ (("South Dakota" . "Pierre")     ("New York" . "Albany")     ("Oregon" . "Salem")     ("Florida" . "Miami")) ;; And we got Florida wrong. (set! capitals       (assoc-set! capitals "Florida" "Tallahassee")) capitals ⇓ (("South Dakota" . "Pierre")     ("New York" . "Albany")     ("Oregon" . "Salem")     ("Florida" . "Tallahassee")) ;; After Oregon secedes, we can remove it. (set! capitals       (assoc-remove! capitals "Oregon")) capitals ⇓ (("South Dakota" . "Pierre")     ("New York" . "Albany")     ("Florida" . "Tallahassee"))
>
>
>
>  
>
>               
>                                                 深圳大学                                  
>                                                                     陈
>                                                 有骏

Your message is really hard to read, I cannot make heads or tails of the
formatting.  Could you please resend it formatted in a normal way?  In
particular, wrapping your text to 72 characters and properly formatting
the code example will improve the readability a lot.

Have a nice day,
Tomas Volf

-- 
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.




Information forwarded to bug-guile <at> gnu.org:
bug#32841; Package guile. (Tue, 22 Oct 2024 03:50:02 GMT) Full text and rfc822 format available.

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

From: "п" <2024110144 <at> mails.szu.edu.cn>
To: "32841" <32841 <at> debbugs.gnu.org>
Subject: Re: bug#32841: assoc-set fails with dot notation association list
Date: Tue, 22 Oct 2024 11:48:53 +0800
[Message part 1 (text/plain, inline)]
The thread and all replies were in 2018. Six years later, in 2024, Anyone opening the up-to-date online manual still sees the old bad code there! The manual is not adjusted even though previous emails had pointed the cause and solution out!
Could anyone take action to edit          api-data.texi&nbsp;&nbsp;in guile's git savannah repo by replacing the bad code in @node Alist Example to a good one, using list and cons instead of directly quoting?

                    
                                                ڴѧ                                  
                                                                    п
[Message part 2 (text/html, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#32841; Package guile. (Tue, 22 Oct 2024 17:52:01 GMT) Full text and rfc822 format available.

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

From: lloda <lloda <at> sarc.name>
To: 陈有骏 <2024110144 <at> mails.szu.edu.cn>,
 "bug-guile <at> gnu.org" <bug-guile <at> gnu.org>
Cc: 32841-done <at> debbugs.gnu.org
Subject: Re: bug#32841: assoc-set fails with dot notation association list
Date: Tue, 22 Oct 2024 19:51:00 +0200
Fixed in 818b879b2e481943340e86dbb5b93f12021206c5.

Thanks

  lloda





Reply sent to lloda <lloda <at> sarc.name>:
You have taken responsibility. (Tue, 22 Oct 2024 17:52:02 GMT) Full text and rfc822 format available.

Notification sent to "Hood, Christopher L." <Christopher.Hood <at> gtri.gatech.edu>:
bug acknowledged by developer. (Tue, 22 Oct 2024 17:52:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 20 Nov 2024 12:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 54 days ago.

Previous Next


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