unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* list-set! Wrong type argument in position 1 (expecting mutable pair)
@ 2020-08-26 20:12 mbcladwell
  2020-08-26 20:42 ` John Cowan
  2020-08-26 20:43 ` Linus Björnstam
  0 siblings, 2 replies; 3+ messages in thread
From: mbcladwell @ 2020-08-26 20:12 UTC (permalink / raw)
  To: guile-user


Hi,
One shortcoming I find working with Guile is the limited number of  
examples of how to use code. Consider list-set!. The only reference in  
the entire Guile manual is the definition in section 6.6.9.6 List  
Modification. If I google I find  
https://docs.racket-lang.org/reference/pairs.html which gives me the  
example (list-set '(zero one two) 2 "two") ==> '(zero one "two") which  
is what I deduced from the Guile manual.  If I try something similar  
in Guile:

scheme@(guile-user)> (list-set! '("zero" "one" "twooooo") 2 "two")
ice-9/boot-9.scm:1669:16: In procedure raise-exception:
In procedure set-car!: Wrong type argument in position 1 (expecting  
mutable pair): ("twooooo")

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> ,bt
            1 (list-set! ("zero" "one" "twooooo") 2 "two")
In ice-9/boot-9.scm:
1669:16  0 (raise-exception _ #:continuable? _)

Could someone provide me with an example of how to use list-set! ?
Alternatively what I really need is how to modify a specified element  
in a list.
Thanks
Mortimer




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

* Re: list-set! Wrong type argument in position 1 (expecting mutable pair)
  2020-08-26 20:12 list-set! Wrong type argument in position 1 (expecting mutable pair) mbcladwell
@ 2020-08-26 20:42 ` John Cowan
  2020-08-26 20:43 ` Linus Björnstam
  1 sibling, 0 replies; 3+ messages in thread
From: John Cowan @ 2020-08-26 20:42 UTC (permalink / raw)
  To: mbcladwell; +Cc: guile-user

First of all, Racket's pairs are immutable, so it provides list-set
(non-destructive) rather than list-set!.

Second, it is an error to mutate a literal, since that amounts to
self-modifying code.  Some Schemes don't enforce that, but Guile does.  So
you need (list-set! (list "one" "twoooo" three") 2 "two"), which constructs
the list at run time using the list function.

On Wed, Aug 26, 2020 at 4:13 PM <mbcladwell@stihie.net> wrote:

>
> Hi,
> One shortcoming I find working with Guile is the limited number of
> examples of how to use code. Consider list-set!. The only reference in
> the entire Guile manual is the definition in section 6.6.9.6 List
> Modification. If I google I find
> https://docs.racket-lang.org/reference/pairs.html which gives me the
> example (list-set '(zero one two) 2 "two") ==> '(zero one "two") which
> is what I deduced from the Guile manual.  If I try something similar
> in Guile:
>
> scheme@(guile-user)> (list-set! '("zero" "one" "twooooo") 2 "two")
> ice-9/boot-9.scm:1669:16: In procedure raise-exception:
> In procedure set-car!: Wrong type argument in position 1 (expecting
> mutable pair): ("twooooo")
>
> Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
> scheme@(guile-user) [1]> ,bt
>             1 (list-set! ("zero" "one" "twooooo") 2 "two")
> In ice-9/boot-9.scm:
> 1669:16  0 (raise-exception _ #:continuable? _)
>
> Could someone provide me with an example of how to use list-set! ?
> Alternatively what I really need is how to modify a specified element
> in a list.
> Thanks
> Mortimer
>
>
>


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

* Re: list-set! Wrong type argument in position 1 (expecting mutable pair)
  2020-08-26 20:12 list-set! Wrong type argument in position 1 (expecting mutable pair) mbcladwell
  2020-08-26 20:42 ` John Cowan
@ 2020-08-26 20:43 ` Linus Björnstam
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Björnstam @ 2020-08-26 20:43 UTC (permalink / raw)
  To: mbcladwell, guile-user

Literals are immutable. (list-set! '(1 2 3) 1 0) -> error.

(list-set! (list 1 2 3) 1 0) -> works

-- 
  Linus Björnstam

On Wed, 26 Aug 2020, at 22:12, mbcladwell@stihie.net wrote:
> 
> Hi,
> One shortcoming I find working with Guile is the limited number of  
> examples of how to use code. Consider list-set!. The only reference in  
> the entire Guile manual is the definition in section 6.6.9.6 List  
> Modification. If I google I find  
> https://docs.racket-lang.org/reference/pairs.html which gives me the  
> example (list-set '(zero one two) 2 "two") ==> '(zero one "two") which  
> is what I deduced from the Guile manual.  If I try something similar  
> in Guile:
> 
> scheme@(guile-user)> (list-set! '("zero" "one" "twooooo") 2 "two")
> ice-9/boot-9.scm:1669:16: In procedure raise-exception:
> In procedure set-car!: Wrong type argument in position 1 (expecting  
> mutable pair): ("twooooo")
> 
> Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
> scheme@(guile-user) [1]> ,bt
>             1 (list-set! ("zero" "one" "twooooo") 2 "two")
> In ice-9/boot-9.scm:
> 1669:16  0 (raise-exception _ #:continuable? _)
> 
> Could someone provide me with an example of how to use list-set! ?
> Alternatively what I really need is how to modify a specified element  
> in a list.
> Thanks
> Mortimer
> 
> 
>



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

end of thread, other threads:[~2020-08-26 20:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-26 20:12 list-set! Wrong type argument in position 1 (expecting mutable pair) mbcladwell
2020-08-26 20:42 ` John Cowan
2020-08-26 20:43 ` Linus Björnstam

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