[R6RS] Should `open-bytes-input-port' copy its argument?

William D Clinger will at ccs.neu.edu
Thu Aug 24 12:53:04 EDT 2006


Should `open-bytes-input-port' copy its argument?

Mike wrote:
> Subject says all.  (Will spotted this.)  My idea was that it should,
> just like `open-bytes-reader'.  Other preference anyone?

That would be my preference also.  For rationale,
see Java's ConcurrentModificationException, and
try to understand this is much more scrumptious
than Sun's documentation makes it sound.  In
particular, the scrumptiousness comes up all the
time in sequential code, even without concurrency.

In my opinion, open-string-input-port should also
be required to copy (or to behave the same as if
it had copied; it wouldn't have to copy immutable
strings, and could copy mutable strings on write).
Without that requirement, string input ports would
exhibit all of the scrumptiousness seen in files.

Consider this:

    (let* ((str (string #\x03c3 #\space))
           (port (open-string-input-port str))
           (b0 (get-u8 port))
           (b1 (lookahead-u8 port))
           (ignored (string-set! str 0 #\a))
           (b1a (get-u8 port))
           (c1  (lookahead-char port))
           (ignored (string-set! str 1 #\a))
           (c1a (get-char port)))
      (list b0 b1 b1a c1 c1a))

With the semantics I prefer, the above evaluates
to (103 131 131 #\space #\space).  Without the copy,
my head hurts just to think of all the scrumptious
things it might do.

Will



More information about the R6RS mailing list