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

bil at ccrma.Stanford.EDU bil at ccrma.Stanford.EDU
Thu Dec 8 13:12:26 PST 2022

I didn't notice that read-bytevector should return #<eof>
if no bytes are read.  Here are changes to r7rs.scm that
make your code work I think (but I doubt it's faster):

< 	 (if (= i start) #<eof> i))
> 	 (if (< i lim)
> 	     (copy (subvector bv 0 i))
> 	     bv))
< (define* (read-bytevector k port)
<   (let* ((buf (make-byte-vector k))
< 	 (bytes (read-bytevector! buf port)))
<     (if (eof-object? bytes)
< 	bytes
< 	(if (= k bytes)
< 	    buf
< 	    (subvector buf 0 bytes)))))
> (define* (read-bytevector k port) (read-bytevector! (make-byte-vector 
> k) port))

A small thing: I'd write your loop

     (do ((buffer (read-bytevector buffer-size source) (read-bytevector 
buffer-size source)))

Starting with (bytevector) looks pointless.

s7test.scm has a version of copy-file (line 100143) that uses
libc functions and which I would expect to be fast.

More information about the Cmdist mailing list