guile-devel
[Top][All Lists]
Advanced

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

Fwd: string is read-only


From: Damien Mattei
Subject: Fwd: string is read-only
Date: Wed, 3 Aug 2022 11:51:49 +0200



---------- Forwarded message ---------
From: Damien Mattei <damien.mattei@gmail.com>
Date: Wed, Aug 3, 2022 at 11:51 AM
Subject: Re: string is read-only
To: Thomas Morley <thomasmorley65@gmail.com>


ok
and i suppose it is the standard, i have been confused by other schemes or racket where my code worked:
CHICKEN
(c) 2008-2019, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 5.1.0 (rev 8e62f718)
linux-unix-gnu-x86-64 [ 64bit dload ptables ]

#;1> 3
3
#;2> (define str2 "hello")
#;3> (string-set! str2 4 #\a)
#;4> str2
"hella"

but not with Racket and #lang R5RS:
Bienvenue dans DrRacket, version 7.7 [3m].
Langage: R5RS; limite mémoire : 128 MB.
> (define str2 "hello")
> (string-set! str2 4 #\a)
. . string-set!: contract violation
  expected: (and/c string? (not/c immutable?))
  given: "hello"
  argument position: 1st
  other arguments...:
> string-copy
#<procedure:string-copy>

not in Gauche scheme too...
and as i making string supported by my Scheme+ i had doubt about it also :-) but it works well :

scheme@(guile-user)> (use-modules (Scheme+))
scheme@(guile-user)> {str <+ (string-copy "hello")}
"hello"
scheme@(guile-user)> {str[4]}
#\o
scheme@(guile-user)> {str[4] <- #\a}
#\a
scheme@(guile-user)> str
"hella"

thanks
Damien


On Wed, Aug 3, 2022 at 11:32 AM Thomas Morley <thomasmorley65@gmail.com> wrote:
Am Mi., 3. Aug. 2022 um 11:13 Uhr schrieb Damien Mattei
<damien.mattei@gmail.com>:
>
> GNU Guile 3.0.1
> Copyright (C) 1995-2020 Free Software Foundation, Inc.
>
> Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
> This program is free software, and you are welcome to redistribute it
> under certain conditions; type `,show c' for details.
>
> Enter `,help' for help.
> 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"
>
> Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
> scheme@(guile-user) [1]> ,q
> scheme@(guile-user)> (string? str2)
> #t
>
> is it a bug in Guile ? :-O
>
> i can only find reference to deprecated read-only string in old doc:
> https://www.gnu.org/software/guile/docs/docs-1.6/guile-ref/Read-Only-Strings.html#Read%20Only%20Strings
>
> Regards,
>
> Damien

Looks you need to do:

(define str2 (string-copy "hello"))
(string-set! str2 4 #\a)

Cheers,
  Harm

reply via email to

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