[Top][All Lists]

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

Re: Guile: What's wrong with this?

From: Noah Lavine
Subject: Re: Guile: What's wrong with this?
Date: Thu, 5 Jan 2012 21:38:58 -0500

Hello all,

I must admit that I do not know much about why R5RS says that literals
are constant, but I think there is a misunderstanding.

Bruce does not want `define' to always copy its result. I think what
he wants is for literals embedded in source code to be mutable. This
would, of course, imply that each literal in the source code would be
a new copy, even if they were identical.

Weirdly enough, that is how my intuition works too. After all, if I
made a string object in Scheme without going to any trouble, I would
get a mutable object. If I write down a string, I expect to get the
same sort of object. Bruce is also right that this enables quick and
easy programming that munges strings.

And I think the argument about putting strings in constant memory is
bad - constant memory is an implementation detail. If it happens that
we can store literals more efficiently when they are not mutated, then
perhaps we should just detect that case and switch representations.

Of course there is a trade-off here between ease of implementation and
ease of use. This change seems pretty unimportant to me, especially if
Python does all right with immutable strings, so I do not think it's
important for us to support it. I just don't buy the arguments against
supporting it.


On Thu, Jan 5, 2012 at 8:41 PM, Mark H Weaver <address@hidden> wrote:
> Mike Gran <address@hidden> writes:
>> It is curious that action of 'copy' really means the
>> action of 'create a copy with different properties'.
>> Shouldn't (string-copy "a") create another immutable string?
> Why would you want to copy an immutable string?
>> Likewise, shouldn't (substring "abc" 1) return an immutable substring?
> As I understand it, in the Scheme standards (at least before R6RS's
> immutable pairs) the rationale behind marking literal constants as
> immutable is solely to avoid needlessly making copies of those literals,
> while flagging accidental attempts to modify them, since that is almost
> certainly a mistake.
> If that is the only rationale for marking things read-only, then there's
> no reason to mark copies read-only.  The philosophy of Scheme (at least
> before R6RS) was clearly to make almost all data structures mutable.
> Following that philosophy, in Guile, even though (substring "abc" 1)
> postpones copying the string buffer, it must create a new heap object.
> Once you've done that, it is feasible to implement copy-on-write.
> Now, the immutable pairs of R6RS and Racket have an entirely different
> rationale, namely that they enable vastly more effective optimization in
> a compiler.  In this case, presumably you'd want copies to retain the
> immutability.
>     Mark

reply via email to

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