#193208 stalin: list->string fails when given character 0

Package:
stalin
Source:
stalin
Description:
An extremely aggressive Scheme compiler
Submitter:
Alejandro Forero Cuervo
Date:
2015-06-27 23:06:07 UTC
Severity:
wishlist
#193208#5
Date:
2003-05-13 17:50:55 UTC
From:
To:
Calls to list->string fail when character 0 is included in the list
passed as its first argument, as in:

  (list->string (list (integer->char 0) #\a))

The  code above  generates the  following runtime  error for  the
resulting program:

Guile does run that code without problems.

Why make it  impossible for strings to hold character  0 on them?
It  makes it  problematic  to create  code  to read/write  binary
files.

#193208#8
Date:
2003-05-14 17:24:02 UTC
From:
To:
(Please preserve the -forwarded address in any replies.)

Alejandro Forero Cuervo <bachue@bachue.com> writes:

I'll forward this upstream, but standards-wise, I don't think R5RS
Scheme strings are designed or defined to support binary data.  Guile
just happens to.

FWIW, among other things, a standard for strings as binary data
structures (i.e. pretending that Scheme strings have the same
conflation that C does) would have to address issues of character
width (8-bytes, 16-bytes, etc.).  Might be a good topic for a SRFI
discussion (srfi.schemers.org).

#193208#11
Date:
2003-05-15 17:23:45 UTC
From:
To:
The reason for this is that Stalin uses the same representation for strings as
C. Strings are null-terminated and do not have any other length field. This
has advantages and disadvantages. The advantage is that FFI calls to and
returns from C have zero overhead when passing and returning strings. The
disadvantages are:

 1. You can't store nulls in strings.
 2. string-length is O(n) instead of O(1)
 3. bounds checking during string-set! and string-ref are O(n) instead of O(1)

RnRS does not require strings to be able to store nulls. It only defines a
subset of the ascii characters and doesn't even define the bijection between
characters and integers.

So this is not a bug. It is a design tradeoff.

In Stalin, you can use vectors. If you make sure that vectors store only
characters then type inference will get you a vector of bytes headed by a
length field. You can store nulls in this.

    Jeff (http://www.ece.purdue.edu/~qobi)