Subject: Re: Scheme implementation in C++
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 2000/10/20
Newsgroups: comp.lang.scheme
Message-ID: <8spa16$bi902$1@fido.engr.sgi.com>
Frank A. Adrian <fadrian@uswest.net> wrote:
+---------------
| "Rob Warnock" <rpw3@rigden.engr.sgi.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

-----
Rob Warnock, 31-2-510		rpw3@sgi.com
Network Engineering		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		PP-ASEL-IA
Mountain View, CA  94043