Also, a number->u8vector function would be nice. Converting a number to a hex
string, then taking every 2 characters of that and converting that back to a
number, for each element of the u8vector, just to keep me from accessing the
number's bytes directly, just strikes me as terribly roundabout.

(define (number->u8vector num)
  (let ((s (number->string num #x10)))
    (let ((v (make-u8vector (/ (string-length s) 2))))
      (let loop ((s s) (i 0))
        (when (< i (u8vector-length v))
          (u8vector-set! v i (string->number (substring s 0 2) #x10))
          (loop (substring s 2) (+ i 1))))
      v)))

vs

(define (numbers->u8vector num)
  (blob->u8vector (somehow-cast-to-blob (subvector (somehow-cast-to-vector num)
1))))

_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to