guile-devel
[Top][All Lists]
Advanced

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

Re: Guile: What's wrong with this?


From: Mark H Weaver
Subject: Re: Guile: What's wrong with this?
Date: Thu, 05 Jan 2012 20:41:45 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

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]