Frank A. Adrian <firstname.lastname@example.org> wrote:
| "Rob Warnock" <email@example.com> wrote in message
| > Remember that Scheme strings are "counted", not terminated by nulls:
| They don't have to be - that's just an implementation choice.
| I could add null termination to a counted string, storing the length before
| the space I pointed to for the object (as long as the GC understood the
| layout) if I wanted the thing to be more C-compatible. Contrawise, I could
| just null terminate the string and let the length be calculated each time I
| used it. It's just optimization, one way or another.
No, it's not. See my other response. I won't repeat it in full here,
but even if you try to be "C-friendly" with a hidden null termination
[as many Schemes do, actually], the semantics really are *different*!
Storing a null into the middle of a C string changes its length; storing
a null into the middle of a Scheme string *doesn't*! And mustn't! See
R5RS, section 3.4 "Storage Model", where it says:
A string, for example, denotes as many locations as there are
characters in the string. ... A new value may be stored into
one of these locations using the string-set! procedure, but
the string continues to denote the same locations as before.
and 6.3.5 "Strings":
The length of a string is the number of characters that it
contains. This number is an exact, non-negative integer that
is fixed when the string is created.
So while there are several representations that satisfy the Scheme
requirements (and several that don't), the choice of representation
is *not* "just" an optimization issue...
Rob Warnock, 31-2-510 firstname.lastname@example.org
Network Engineering http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
1600 Amphitheatre Pkwy. PP-ASEL-IA
Mountain View, CA 94043