[CM] Copying files using the provided R7RS byte-vector procedures

Rudolf Adamkovič salutis at me.com
Thu Dec 8 06:21:07 PST 2022


Greetings Scheme poets!

So, I wrote a `copy-file' procedure (using just the information found in
the R7RS PDF) that copies a file *byte-by-byte*:

(define (copy-file source destination)
  "Copy SOURCE file as DESTINATION file."
  (let ((source (open-binary-input-file source))
        (destination (open-binary-output-file destination)))
    (do ((byte (read-u8 source) (read-u8 source)))
        ((eof-object? byte))
      (write-u8 byte destination))
    (close-port source)
    (close-port destination)))

The procedure worked on the first try in both Guile and s7.  Happy, I
decided to make the procedure copy *megabyte-by-megabyte* to make it
faster:

(define (copy-file source destination)
  "Copy SOURCE file as DESTINATION file."
  (let ((buffer-size (* 1024 1024))
        (source (open-binary-input-file source))
        (destination (open-binary-output-file destination)))
    (do ((buffer (bytevector) (read-bytevector buffer-size source)))
        ((eof-object? buffer))
      (write-bytevector buffer destination))
    (close-port source)
    (close-port destination)))

The procedure, again, worked on the first try in Guile, and it indeed
copied files much faster.  However, in s7, the procedure seems to never
return!  I waited for a couple of minutes, copying a 5-megabyte file.

Have I stumbled upon a bug in s7 (or `r7rs.scm' that defines the R7RS
byte-vector procedures), or have I written the procedure incorrectly?

Rudy
-- 
"'Contrariwise,' continued Tweedledee, 'if it was so, it might be; and
if it were so, it would be; but as it isn't, it ain't.  That's logic.'"
-- Lewis Carroll, Through the Looking Glass, 1871/1872

Rudolf Adamkovič <salutis at me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia



More information about the Cmdist mailing list