[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string is read-only

From: Damien Mattei
Subject: Re: string is read-only
Date: Wed, 3 Aug 2022 12:55:02 +0200

interesting the ELF file argument :-) ,i understand the idea, like a Turing machine that  protect some part of ribbon...
it is the same thing with arrays
scheme@(guile-user)> (define vct '#(1 2 3))
scheme@(guile-user)> vct
#(1 2 3)
scheme@(guile-user)> (vector-set! vct 1 7)
ice-9/boot-9.scm:1669:16: In procedure raise-exception:
In procedure vector-set!: Wrong type argument in position 1 (expecting mutable vector): #(1 2 3)

works in Chicken scheme:
(define vct '#(1 2 3))
(vector-set! vct 1 7)

but no restrictions with lists in Guile:
scheme@(guile-user)> (define lst '(1 2 3))
scheme@(guile-user)> (set-car! lst 7)
scheme@(guile-user)> lst
(7 2 3)
which seems not logic.(but i recognize the behavior of Scheme of '80 even if i no more use set-car! and set-cdr!)

On Wed, Aug 3, 2022 at 11:41 AM Maxime Devos <> wrote:

On 03-08-2022 11:12, Damien Mattei wrote:
> scheme@(guile-user)> (define str2 "hello")
> scheme@(guile-user)> (string-set! str2 4 #\a)
> ice-9/boot-9.scm:1669:16: In procedure raise-exception:
> string is read-only: "hello"

It's not -- the existence of read-only strings is implied by
substring/read-only, and also see:

>   (guile)Object File format
> Typically all segments of an ELF file are marked as read-only, except
> that part that represents modifiable static data or static data that
> needs load-time initialization.  Loading an ELF file is as simple as
> mmapping the thing into memory with read-only permissions, then using
> the segment table to mark a small sub-region of the file as writable.
> This writable section is typically added to the root set of the garbage
> collector as well.

I'm not aware of explicit documentation that string literals may not be
modified (and in this case, cannot be modified). However, see the
following mail on string mutability and program text:

and maybe surrounding definitions.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]