unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#32841: assoc-set fails with dot notation association list
@ 2018-09-25 20:33 Hood, Christopher L.
  2018-09-25 22:04 ` John Cowan
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Hood, Christopher L. @ 2018-09-25 20:33 UTC (permalink / raw)
  To: 32841

[-- Attachment #1: Type: text/plain, Size: 978 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 4266 bytes --]

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

* bug#32841: assoc-set fails with dot notation association list
  2018-09-25 20:33 bug#32841: assoc-set fails with dot notation association list Hood, Christopher L.
@ 2018-09-25 22:04 ` John Cowan
  2018-09-27  3:02 ` Mark H Weaver
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: John Cowan @ 2018-09-25 22:04 UTC (permalink / raw)
  To: Christopher.Hood; +Cc: 32841

[-- Attachment #1: Type: text/plain, Size: 1367 bytes --]

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@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
>

[-- Attachment #2: Type: text/html, Size: 2803 bytes --]

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

* bug#32841: assoc-set fails with dot notation association list
  2018-09-25 20:33 bug#32841: assoc-set fails with dot notation association list Hood, Christopher L.
  2018-09-25 22:04 ` John Cowan
@ 2018-09-27  3:02 ` Mark H Weaver
  2018-09-27 12:09   ` John Cowan
  2024-10-21  8:54 ` ���п� via Bug reports for GUILE, GNU's Ubiquitous Extension Language
  2024-10-22  3:48 ` ���п� via Bug reports for GUILE, GNU's Ubiquitous Extension Language
  3 siblings, 1 reply; 8+ messages in thread
From: Mark H Weaver @ 2018-09-27  3:02 UTC (permalink / raw)
  To: Hood, Christopher L.; +Cc: 32841

Hi Christopher,

"Hood, Christopher L." <Christopher.Hood@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





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

* bug#32841: assoc-set fails with dot notation association list
  2018-09-27  3:02 ` Mark H Weaver
@ 2018-09-27 12:09   ` John Cowan
  0 siblings, 0 replies; 8+ messages in thread
From: John Cowan @ 2018-09-27 12:09 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: 32841, Christopher.Hood

[-- Attachment #1: Type: text/plain, Size: 627 bytes --]

On Wed, Sep 26, 2018 at 11:03 PM Mark H Weaver <mhw@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@ccil.org
Here lies the Christian, judge, and poet Peter,
Who broke the laws of God and man and metre.

[-- Attachment #2: Type: text/html, Size: 1234 bytes --]

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

* bug#32841: assoc-set fails with dot notation association list
  2018-09-25 20:33 bug#32841: assoc-set fails with dot notation association list Hood, Christopher L.
  2018-09-25 22:04 ` John Cowan
  2018-09-27  3:02 ` Mark H Weaver
@ 2024-10-21  8:54 ` ���п� via Bug reports for GUILE, GNU's Ubiquitous Extension Language
  2024-10-21 20:26   ` Tomas Volf
  2024-10-22  3:48 ` ���п� via Bug reports for GUILE, GNU's Ubiquitous Extension Language
  3 siblings, 1 reply; 8+ messages in thread
From: ���п� via Bug reports for GUILE, GNU's Ubiquitous Extension Language @ 2024-10-21  8:54 UTC (permalink / raw)
  To: 32841

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb18030", Size: 1615 bytes --]

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)       6Í0 ("Oregon" . "Salem") (assoc-ref capitals "Oregon")   6Í0 "Salem" ;; We left out South Dakota. (set! capitals       (assoc-set! capitals "South Dakota" "Pierre")) capitals 6Í0 (("South Dakota" . "Pierre")     ("New York" . "Albany")     ("Oregon" . "Salem")     ("Florida" . "Miami")) ;; And we got Florida wrong. (set! capitals       (assoc-set! capitals "Florida" "Tallahassee")) capitals 6Í0 (("South Dakota" . "Pierre")     ("New York" . "Albany")     ("Oregon" . "Salem")     ("Florida" . "Tallahassee")) ;; After Oregon secedes, we can remove it. (set! capitals       (assoc-remove! capitals "Oregon")) capitals 6Í0 (("South Dakota" . "Pierre")     ("New York" . "Albany")     ("Florida" . "Tallahassee"))



 

              
                                                ÉîÛÚ´óѧ                                  
                                                                    ³ÂÓп¥

[-- Attachment #2: Type: text/html, Size: 7335 bytes --]

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

* bug#32841: assoc-set fails with dot notation association list
  2024-10-21  8:54 ` ���п� via Bug reports for GUILE, GNU's Ubiquitous Extension Language
@ 2024-10-21 20:26   ` Tomas Volf
  0 siblings, 0 replies; 8+ messages in thread
From: Tomas Volf @ 2024-10-21 20:26 UTC (permalink / raw)
  To: 32841; +Cc: .%c2.п.

".%c2.п." via "Bug reports for GUILE, GNU's Ubiquitous
Extension Language" <bug-guile@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.





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

* bug#32841: assoc-set fails with dot notation association list
  2018-09-25 20:33 bug#32841: assoc-set fails with dot notation association list Hood, Christopher L.
                   ` (2 preceding siblings ...)
  2024-10-21  8:54 ` ���п� via Bug reports for GUILE, GNU's Ubiquitous Extension Language
@ 2024-10-22  3:48 ` ���п� via Bug reports for GUILE, GNU's Ubiquitous Extension Language
  2024-10-22 17:51   ` lloda
  3 siblings, 1 reply; 8+ messages in thread
From: ���п� via Bug reports for GUILE, GNU's Ubiquitous Extension Language @ 2024-10-22  3:48 UTC (permalink / raw)
  To: 32841

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb18030", Size: 642 bytes --]

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?

                    
                                                ÉîÛÚ´óѧ                                  
                                                                    ³ÂÓп¥

[-- Attachment #2: Type: text/html, Size: 4681 bytes --]

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

* bug#32841: assoc-set fails with dot notation association list
  2024-10-22  3:48 ` ���п� via Bug reports for GUILE, GNU's Ubiquitous Extension Language
@ 2024-10-22 17:51   ` lloda
  0 siblings, 0 replies; 8+ messages in thread
From: lloda @ 2024-10-22 17:51 UTC (permalink / raw)
  To: 陈有骏, bug-guile@gnu.org; +Cc: 32841-done

Fixed in 818b879b2e481943340e86dbb5b93f12021206c5.

Thanks

  lloda






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

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

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-25 20:33 bug#32841: assoc-set fails with dot notation association list Hood, Christopher L.
2018-09-25 22:04 ` John Cowan
2018-09-27  3:02 ` Mark H Weaver
2018-09-27 12:09   ` John Cowan
2024-10-21  8:54 ` ���п� via Bug reports for GUILE, GNU's Ubiquitous Extension Language
2024-10-21 20:26   ` Tomas Volf
2024-10-22  3:48 ` ���п� via Bug reports for GUILE, GNU's Ubiquitous Extension Language
2024-10-22 17:51   ` lloda

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