unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Tim Van den Langenbergh <tmt_vdl@gmx.com>
To: mbcladwell@stihie.net
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: list-set! Wrong type argument in position 1 (expecting mutable pair)
Date: Wed, 26 Aug 2020 22:22:55 +0200	[thread overview]
Message-ID: <3217080.IVKLgIBuA9@terra> (raw)
In-Reply-To: <20200826151232.Horde.54lAstMht7PXoKcNHhj8vJT@www.stihie.net>

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

Hey,

yeah, a quoted list is immutable (at least in Guile).

You could do something like...

(define my-list (list "zero" "one" "twooo")
(list-set! my-list 2 "two")
my-list

Don't forget that list-set! returns the new element, rather than the modified list.

Cheers,

-Tim

On Wednesday, 26 August 2020 22:12:32 CEST you 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
>

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

           reply	other threads:[~2020-08-26 20:22 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20200826151232.Horde.54lAstMht7PXoKcNHhj8vJT@www.stihie.net>]

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=3217080.IVKLgIBuA9@terra \
    --to=tmt_vdl@gmx.com \
    --cc=guile-devel@gnu.org \
    --cc=mbcladwell@stihie.net \
    /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).