<stephan@pcrm.win.tue.nl> wrote:
+---------------
| You can put the char's in a single array, but that still
| doesn't allow you to find out whether something is a char
| in the first place. And without that, char->integer cannot
| be implemented safely, and char? cannot be implemented at all.
+---------------
Not true! "Char?" *can* be implemented in a totally portable
ANSI C way, just not very efficiently: ;-} ;-}
SCHEME is_char(SCHEME x) {
extern SCHEME standard_chars[];
int i;
for (i = 0; i < NUM_CHARS; ++i)
if (EQ(x, &standard_chars[i]))
return SCHEME_TRUE;
return SCHEME_FALSE;
}
And then you can put the non-portable version of the code that depends
on pointer compare working outside array bounds under a machine-dependent
feature test, and use fast code like:
SCHEME is_char(SCHEME x) {
extern SCHEME standard_chars[];
if ((addr_t)x >= (addr_t)&standard_chars[0] &&
(addr_t)x < (addr_t)&standard_chars[NUM_CHARS])
return SCHEME_TRUE;
return SCHEME_FALSE;
}
+---------------
| >A "single array" is surely the "same array" as itself, no?
|
| You said: a single array for _all the values of a type_.
+---------------
Yes, characters are a type, so one array for all characters.
What's odd about that?
Note that the original context was *only* SIOD-style *preallocated*
types such as chars or booleans (or sub-types, such as small integers),
not for general heap-allocated types.
-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