From 2b947fa3d9a1bdf1a9ecd545107bac8698ea3158 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ludovic=20Court=C3=A8s?= Date: Mon, 6 Apr 2009 22:33:28 +0200 Subject: [PATCH] doc: Add examples. * doc/api-r6rs.texi (Bytevectors as Integers): Add example. (Bytevectors and Integer Lists): Likewise. --- doc/api-r6rs.texi | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/api-r6rs.texi b/doc/api-r6rs.texi index 659a83e..e8b54fd 100644 --- a/doc/api-r6rs.texi +++ b/doc/api-r6rs.texi @@ -105,6 +105,25 @@ Return a newly allocated copy of @var{bv}. The contents of a bytevector can be interpreted as a sequence of integers of any given size, sign, and endianness. +@lisp +(let ((bv (make-bytevector 4))) + (bytevector-u8-set! bv 0 #x12) + (bytevector-u8-set! bv 1 #x34) + (bytevector-u8-set! bv 2 #x56) + (bytevector-u8-set! bv 3 #x78) + + (map (lambda (number) + (number->string number 16)) + (list (bytevector-u8-ref bv 0) + (bytevector-u16-ref bv 0 (endianness big)) + (bytevector-u32-ref bv 0 (endianness little))))) + +@result{} ("12" "1234" "78563412") +@end lisp + +The most generic procedures to interpret bytevector contents as integers +are described below. + @deffn {Scheme Procedure} bytevector-uint-ref bv index endianness size @deffnx {Scheme Procedure} bytevector-sint-ref bv index endianness size @deffnx {C Function} scm_r6rs_bytevector_uint_ref (bv, index, endianness, size) @@ -209,7 +228,13 @@ host's native endianness. @subsection Converting Bytevectors to/from Integer Lists Bytevector contents can readily be converted to/from lists of signed or -unsigned integers using the following procedures. +unsigned integers: + +@lisp +(bytevector->sint-list (u8-list->bytevector (make-list 4 255)) + (endianness little) 2) +@result{} (-1 -1) +@end lisp @deffn {Scheme Procedure} bytevector->u8-list bv @deffnx {C Function} scm_r6rs_bytevector_to_u8_list (bv) -- 2.11.4.GIT