diff --git a/lib/scheme/base.sld b/lib/scheme/base.sld index e19e88ed..d4b6e95c 100644 --- a/lib/scheme/base.sld +++ b/lib/scheme/base.sld @@ -13,7 +13,7 @@ (export * + - ... / < <= = => > >= _ abs and append apply assoc assq assv begin binary-port? boolean? boolean=? bytevector-copy bytevector-copy! - bytevector-copy-partial bytevector-length + bytevector-length bytevector-u8-ref bytevector-u8-set! bytevector? caar cadr call-with-current-continuation call-with-port call-with-values call/cc car case cdr cdar cddr ceiling char->integer @@ -45,7 +45,7 @@ unquote-splicing utf8->string values vector vector->list vector->string vector-copy vector-copy! vector-fill! vector-for-each vector-length vector-map vector-ref vector-set! vector? when with-exception-handler - write-bytevector write-char write-partial-bytevector write-u8 zero?) + write-bytevector write-char write-u8 zero?) (include "define-values.scm" "extras.scm" "misc-macros.scm")) diff --git a/lib/scheme/extras.scm b/lib/scheme/extras.scm index 9a4a361d..c203403b 100644 --- a/lib/scheme/extras.scm +++ b/lib/scheme/extras.scm @@ -72,12 +72,14 @@ (bytevector-u8-set! vec (+ i start) (bytevector-u8-ref res i)))))))) (define (write-bytevector vec . o) - (write-string (utf8->string vec) (bytevector-length vec) (if (pair? o) (car o) (current-output-port)))) - -(define (write-partial-bytevector vec start end . o) - (if (zero? start) - (apply write-bytevector vec end o) - (apply write-bytevector (bytevector-copy-partial vec start end) o))) + (let* ((out (if (pair? o) (car o) (current-output-port))) + (o (if (pair? o) (cdr o) '())) + (start (if (pair? o) (car o) 0)) + (o (if (pair? o) (cdr o) '())) + (end (if (pair? o) (car o) (bytevector-length vec)))) + (do ((i start (+ i 1))) + ((>= i end)) + (write-u8 (bytevector-u8-ref vec i) out)))) (define (make-list n . o) (let ((init (and (pair? o) (car o)))) @@ -128,11 +130,6 @@ (define (string->vector vec) (list->vector (string->list vec))) -(define (bytevector-copy bv) - (let ((res (make-bytevector (bytevector-length bv)))) - (bytevector-copy! bv res) - res)) - (define (bytevector-copy! to at from . o) (let ((start (if (pair? o) (car o) 0)) (end (if (and (pair? o) (pair? (cdr o))) @@ -142,7 +139,10 @@ ((>= j end)) (bytevector-u8-set! to i (bytevector-u8-ref from j))))) -(define bytevector-copy-partial subbytes) +(define (bytevector-copy vec . o) + (if (null? o) + (subbytes vec 0) + (apply subbytes vec o))) ;; Never use this! (define (string-copy! to at from . o)