Email list hosting service & mailing list manager

istring? Marc Nieper-Wißkirchen (15 Jul 2016 12:36 UTC)
Re: istring? Per Bothner (15 Jul 2016 14:25 UTC)
Re: istring? John Cowan (15 Jul 2016 15:53 UTC)
Re: istring? John Cowan (15 Jul 2016 14:59 UTC)
Re: istring? Per Bothner (15 Jul 2016 15:47 UTC)
Re: istring? John Cowan (15 Jul 2016 16:18 UTC)
Re: istring? Marc Nieper-Wißkirchen (16 Jul 2016 13:19 UTC)
Re: istring? John Cowan (16 Jul 2016 15:14 UTC)

Re: istring? Per Bothner 15 Jul 2016 14:25 UTC


On 07/15/2016 05:36 AM, Marc Nieper-Wißkirchen wrote:
> First of all, thank you for your proposal.
>
> I am wondering whether a predicate like `istring?' should really be part of the standard (also to make the transition from R7RS-small easier). Without `istring?' implementations are still possible that make no difference between mutable and immutable strings. (Of course, the programmer still needs to distinguish between effectively immutable strings and mutable ones.)

Technically.  R7RS says "It is an error to attempt to store a new value into a location that
is denoted by an immutable object" rather than "an error is signaled".  So an implementation *could*
allow:
    (define v "abc")
    (string-set! v 0 #\A)
but I think we can agree the "quality-of-implemention" would be low if that were allowed.

An implementation could protect against mutating a constant by putting the
constant in a write-protected page, in which case implementing istring? would
be difficult - but if an implementation can control page protections,
then it should be able to query page protections.

Use-case I can think of for istring? would be
(1)better error check an better error messages;
(2) algorithm selection: if you know string-ref is constant-time
you might implement a procedure (for example a search) differently
than if you don't know that.

These use-cases are somewhat contradictory if 'istring?" means both
constant-time *and* immutable.

But mainly, I just followed SRFI-135 here.
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/