guile-devel
[Top][All Lists]
Advanced

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

Re: string is read-only


From: Taylan Kammer
Subject: Re: string is read-only
Date: Wed, 3 Aug 2022 12:30:50 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0

On 03.08.2022 11:50, Jean Abou Samra wrote:
> 
> 
>> Le 3 août 2022 à 11:49, Taylan Kammer <taylan.kammer@gmail.com> a écrit :
>>
>> On 03.08.2022 11:12, Damien Mattei wrote:
>>> 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
>>>  
>>> <https://www.gnu.org/software/guile/docs/docs-1.6/guile-ref/Read-Only-Strings.html#Read%20Only%20Strings>
>>>
>>> Regards,
>>>
>>> Damien
>>
>> String literals are constants, and it's intentional.
>>
>> I'm not sure if it's mentioned anywhere in the manual.
>>
>> If you want to get a mutable string from a literal, you can use:
>>
>>  (define str (string-copy "foobar"))
>>
>> -- 
>> Taylan
> 
> This is standard. See the intro of
> 
> https://srfi.schemers.org/srfi-135/ <https://srfi.schemers.org/srfi-135/>
> 
>>

This SRFI defines a new data type, which is not really relevant here.

As far as I know, Guile doesn't support it yet anyway.

-- 
Taylan



reply via email to

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