summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2023-01-06 17:46:06 +0100
committerLudovic Courtès <ludo@gnu.org>2023-01-14 16:14:17 +0100
commite441c34f1666921f6b15597c1aa3a50596a129d7 (patch)
tree8e7a4a443b800118ee034e00d5888a9d9044d7e6 /doc
parent54ee636e57dd9416dea3e70be6e60f9bb9a22ebf (diff)
downloadguile-e441c34f1666921f6b15597c1aa3a50596a129d7.tar.gz
Add 'bytevector-slice'.
* module/rnrs/bytevectors/gnu.scm: New file. * am/bootstrap.am (SOURCES): Add it. * libguile/bytevectors.c (scm_bytevector_slice): New function. * libguile/bytevectors.h (scm_bytevector_slice): New declaration. * test-suite/tests/bytevectors.test ("bytevector-slice"): New tests. * doc/ref/api-data.texi (Bytevector Slices): New node.
Diffstat (limited to 'doc')
-rw-r--r--doc/ref/api-data.texi46
-rw-r--r--doc/ref/guile.texi2
2 files changed, 46 insertions, 2 deletions
diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index 30190f315..d332aa997 100644
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -1,6 +1,6 @@
@c -*-texinfo-*-
@c This is part of the GNU Guile Reference Manual.
-@c Copyright (C) 1996, 1997, 2000-2004, 2006-2017, 2019-2020, 2022
+@c Copyright (C) 1996, 1997, 2000-2004, 2006-2017, 2019-2020, 2022-2023
@c Free Software Foundation, Inc.
@c See the file guile.texi for copying conditions.
@@ -6673,6 +6673,7 @@ Bytevectors can be used with the binary input/output primitives
* Bytevectors as Strings:: Interpreting bytes as Unicode strings.
* Bytevectors as Arrays:: Guile extension to the bytevector API.
* Bytevectors as Uniform Vectors:: Bytevectors and SRFI-4.
+* Bytevector Slices:: Aliases for parts of a bytevector.
@end menu
@node Bytevector Endianness
@@ -7108,6 +7109,49 @@ Bytevectors may also be accessed with the SRFI-4 API. @xref{SRFI-4 and
Bytevectors}, for more information.
+@node Bytevector Slices
+@subsubsection Bytevector Slices
+
+@cindex subset, of a bytevector
+@cindex slice, of a bytevector
+@cindex slice, of a uniform vector
+As an extension to the R6RS specification, the @code{(rnrs bytevectors
+gnu)} module provides the @code{bytevector-slice} procedure, which
+returns a bytevector aliasing part of an existing bytevector.
+
+@deffn {Scheme Procedure} bytevector-slice @var{bv} @var{offset} [@var{size}]
+@deffnx {C Function} scm_bytevector_slice (@var{bv}, @var{offset}, @var{size})
+Return the slice of @var{bv} starting at @var{offset} and counting
+@var{size} bytes. When @var{size} is omitted, the slice covers all
+of @var{bv} starting from @var{offset}. The returned slice shares
+storage with @var{bv}: changes to the slice are visible in @var{bv}
+and vice-versa.
+
+When @var{bv} is actually a SRFI-4 uniform vector, its element
+type is preserved unless @var{offset} and @var{size} are not aligned
+on its element type size.
+@end deffn
+
+Here is an example showing how to use it:
+
+@lisp
+(use-modules (rnrs bytevectors)
+ (rnrs bytevectors gnu))
+
+(define bv (u8-list->bytevector (iota 10)))
+(define slice (bytevector-slice bv 2 3))
+
+slice
+@result{} #vu8(2 3 4)
+
+(bytevector-u8-set! slice 0 77)
+slice
+@result{} #vu8(77 3 4)
+
+bv
+@result{} #vu8(0 1 77 3 4 5 6 7 8 9)
+@end lisp
+
@node Arrays
@subsection Arrays
@tpindex Arrays
diff --git a/doc/ref/guile.texi b/doc/ref/guile.texi
index 6a81a0893..8414c3e2d 100644
--- a/doc/ref/guile.texi
+++ b/doc/ref/guile.texi
@@ -13,7 +13,7 @@
@copying
This manual documents Guile version @value{VERSION}.
-Copyright (C) 1996-1997, 2000-2005, 2009-2021 Free Software Foundation,
+Copyright (C) 1996-1997, 2000-2005, 2009-2023 Free Software Foundation,
Inc. @*
Copyright (C) 2021 Maxime Devos