[R6RS] `make-bytes' with fill argument

William D Clinger will at ccs.neu.edu
Sun Jun 25 14:43:23 EDT 2006

Mike wrote:
> (make-bytes n fill) has the problem that it's unclear of what type
> `fill' is.  I added (make-u8-bytes n fill) instead.

That's excessively anal.  Bytes objects are inherently
polymorphic, so their creator should be polymorphic at
least to the extent of accepting either signed or unsigned
l, as in

(define (make-bytes n . rest)
  ; Take your choice of these predicates.
  (define (fill-acceptable? x)
    (and (fixnum? x) (<= -128 x 255)))
  (cond ((null? rest)
         (make-u8-bytes n 0))
        ((null? (cdr rest))
         (let ((fill (car rest)))
           (if (fill-acceptable? fill)
               (make-u8-bytes n (mod fill 256))
               (error ...))))
        (else ...)))

More permissive choices for fill-acceptable? would be
more useful (e.g. to allow any fixnum or exact integer),
but usefulness and generality might conflict with the
spirit of R6RS.

I'd just as soon leave make-u8-bytes out altogether,
but if we're going to have it we might as well have
all three (make-bytes, make-u8-bytes, make-s8-bytes).


More information about the R6RS mailing list