guile-devel
[Top][All Lists]
Advanced

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

Re: The empty string and other empty strings


From: Mark H Weaver
Subject: Re: The empty string and other empty strings
Date: Tue, 10 Jan 2012 11:15:06 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

David Kastrup <address@hidden> writes:

> Mark H Weaver <address@hidden> writes:
>
>> I went ahead and committed this optimization.  Empty substrings are now
>> always freshly allocated, and never hold a reference to the original
>> stringbuf.
>
> Why would they need an allocation at all?  They don't contain
> characters.

It is an arguable point, but although they don't contain characters,
they can still be compared with other objects using `eq?'.

The R5RS says that `string', `make-string', `substring',
`string-append', `list->string', and `string-copy' return a newly
allocated string, which implies that the returned string is not `eq?' to
any other existing object.

Admittedly, the R5RS also says that `list' returns a newly allocated
list, which obviously cannot be true for the empty list.

Nonetheless, it still seems safer to strictly follow the standard here.
I expect that most implementations produce newly allocated empty strings
(since that's what naturally happens unless you handle empty strings
specially) and some programs might depend on this behavior, especially
since the standard seems to mandate it.

On the other hand, I don't expect that enough empty strings are created
to make the optimization very significant, though perhaps I'm mistaken.
Empty string literals ("") will still be shared, for what it's worth.

What do other people think?

    Mark



reply via email to

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