klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

Bytevectors.html (10242B)


      1 <html lang="en">
      2 <head>
      3 <title>Bytevectors - klisp Reference Manual</title>
      4 <meta http-equiv="Content-Type" content="text/html">
      5 <meta name="description" content="klisp Reference Manual">
      6 <meta name="generator" content="makeinfo 4.13">
      7 <link title="Top" rel="start" href="index.html#Top">
      8 <link rel="prev" href="Vectors.html#Vectors" title="Vectors">
      9 <link rel="next" href="Errors.html#Errors" title="Errors">
     10 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
     11 <meta http-equiv="Content-Style-Type" content="text/css">
     12 <style type="text/css"><!--
     13   pre.display { font-family:inherit }
     14   pre.format  { font-family:inherit }
     15   pre.smalldisplay { font-family:inherit; font-size:smaller }
     16   pre.smallformat  { font-family:inherit; font-size:smaller }
     17   pre.smallexample { font-size:smaller }
     18   pre.smalllisp    { font-size:smaller }
     19   span.sc    { font-variant:small-caps }
     20   span.roman { font-family:serif; font-weight:normal; } 
     21   span.sansserif { font-family:sans-serif; font-weight:normal; } 
     22 --></style>
     23 <link rel="stylesheet" type="text/css" href="css/style.css">
     24 </head>
     25 <body>
     26 <div class="node">
     27 <a name="Bytevectors"></a>
     28 <p>
     29 Next:&nbsp;<a rel="next" accesskey="n" href="Errors.html#Errors">Errors</a>,
     30 Previous:&nbsp;<a rel="previous" accesskey="p" href="Vectors.html#Vectors">Vectors</a>,
     31 Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
     32 <hr>
     33 </div>
     34 
     35 <!-- node-name,  next,  previous,  up -->
     36 <h2 class="chapter">19 Bytevectors</h2>
     37 
     38 <p><a name="index-Bytevectors-370"></a>
     39 A bytevector is an object that contains a sequence of bytes, that is,
     40 exact integers between 0 and 255 inclusive.  A bytevector has a length
     41 that is fixed at creation time, and as many bytes, indexed from
     42 <code>0</code> to <code>length-1</code>.  Compared to vectors, bytevectors use
     43 less size for each element.
     44 
     45    <p>Bytevectors may be mutable or immutable.  If an attempt is made to
     46 mutate an immutable bytevector, an error is signaled.  Two immutable
     47 bytevectors are &ldquo;eq?&rdquo; iff they are &ldquo;equal?&rdquo;.  Two mutable
     48 bytevectors are &ldquo;eq?&rdquo; if they were created by the same constructor
     49 call.  Two mutable bytevectors are &ldquo;equal?&rdquo; iff they have the same
     50 length and have &ldquo;equal?&rdquo;  bytes in each position.  There is only one
     51 empty bytevector (that is, a bytevector of length 0) and that
     52 bytevector is immutable.  The bytevector type is encapsulated.
     53 
     54    <p>SOURCE NOTE: The report doesn't currently include bytevectors. They
     55 are taken from r7rs scheme.
     56 
     57 <div class="defun">
     58 &mdash; Applicative: <b>bytevector?</b> (<var>bytevector? . obje</var>)<var><a name="index-bytevector_003f-371"></a></var><br>
     59 <blockquote><p>The primitive type predicate for type bytevector.  <code>bytevector?</code>
     60 returns true iff all the objects in <code>objects</code> are of type
     61 bytevector. 
     62 </p></blockquote></div>
     63 
     64 <div class="defun">
     65 &mdash; Applicative: <b>immutable-bytevector?</b> (<var>immutable-bytevector? objects</var>)<var><a name="index-immutable_002dbytevector_003f-372"></a></var><br>
     66 &mdash; Applicative: <b>mutable-bytevector?</b> (<var>mutable-bytevector? objects</var>)<var><a name="index-mutable_002dbytevector_003f-373"></a></var><br>
     67 <blockquote><p>The primitive type predicates for types immutable bytevector and
     68 mutable bytevector.  These return true iff all the objects in
     69 <code>objects</code> are of type immutable bytevector or mutable bytevector
     70 respectively. 
     71 </p></blockquote></div>
     72 
     73 <div class="defun">
     74 &mdash; Applicative: <b>make-bytevector</b> (<var>make-bytevector k </var>[<var>u8</var>])<var><a name="index-make_002dbytevector-374"></a></var><br>
     75 <blockquote><p>Applicative <code>make-bytevector</code> constructs and returns a new
     76 mutable bytevector of length <code>k</code>.  If <code>u8</code> is specified,
     77 then all bytes in the returned bytevector are <code>obj</code>, otherwise
     78 the content of the bytevector is unspecified. 
     79 </p></blockquote></div>
     80 
     81 <div class="defun">
     82 &mdash; Applicative: <b>bytevector-length</b> (<var>bytevector-length bytevector</var>)<var><a name="index-bytevector_002dlength-375"></a></var><br>
     83 <blockquote><p>Applicative <code>bytevector-length</code> returns the length of
     84 <code>bytevector</code>. 
     85 </p></blockquote></div>
     86 
     87 <div class="defun">
     88 &mdash; Applicative: <b>bytevector-ref</b> (<var>bytevector-ref bytevector k</var>)<var><a name="index-bytevector_002dref-376"></a></var><br>
     89 <blockquote><p>Applicative <code>bytevector-ref</code> returns the byte of
     90 <code>bytevector</code> at position <code>k</code>.  If <code>k</code> is out of bounds
     91 (i.e. less than <code>0</code> or greater or equal than
     92 <code>(bytevector-length bytevector)</code>) an error is signaled. 
     93 </p></blockquote></div>
     94 
     95 <div class="defun">
     96 &mdash; Applicative: <b>bytevector-set!</b> (<var>bytevector-set! bytevector k u8</var>)<var><a name="index-bytevector_002dset_0021-377"></a></var><br>
     97 <blockquote><p>Applicative <code>bytevector-set!</code> replaces the byte with index
     98 <code>k</code> in <code>bytevector</code> with byte <code>u8</code>.  If <code>k</code> is out
     99 of bounds, or <code>bytevector</code> is immutable, an error is
    100 signaled. The result returned by <code>bytevector-set!</code> is inert. 
    101 </p></blockquote></div>
    102 
    103 <div class="defun">
    104 &mdash; Applicative: <b>bytevector</b> (<var>bytevector . u8s</var>)<var><a name="index-bytevector-378"></a></var><br>
    105 <blockquote><p>Applicative <code>bytevector</code> contructs and return a new mutable
    106 bytevector composed of the byte arguments. 
    107 </p></blockquote></div>
    108 
    109 <div class="defun">
    110 &mdash; Applicative: <b>bytevector-&gt;list</b> (<var>bytevector-&gt;list bytevector</var>)<var><a name="index-bytevector_002d_003elist-379"></a></var><br>
    111 &mdash; Applicative: <b>list-&gt;bytevector</b> (<var>list-&gt;bytevector u8s</var>)<var><a name="index-list_002d_003ebytevector-380"></a></var><br>
    112 <blockquote><p>These applicatives convert between bytevectors and lists of bytes.  If
    113 the list passed to <code>list-&gt;bytevector</code> contains an object that
    114 isn't a byte, an error is signaled.  The objects returned by these
    115 applicatives are always mutable. 
    116 </p></blockquote></div>
    117 
    118 <div class="defun">
    119 &mdash; Applicative: <b>bytevector-copy</b> (<var>bytevector-copy bytevector</var>)<var><a name="index-bytevector_002dcopy-381"></a></var><br>
    120 <blockquote><p>Applicative <code>bytevector-copy</code> constructs and returns a new
    121 mutable bytevector with the same length and bytes as
    122 <code>bytevector</code>. 
    123 </p></blockquote></div>
    124 
    125 <div class="defun">
    126 &mdash; Applicative: <b>bytevector-&gt;vector</b> (<var>bytevector-&gt;vector bytevector</var>)<var><a name="index-bytevector_002d_003evector-382"></a></var><br>
    127 &mdash; Applicative: <b>vector-&gt;bytevector</b> (<var>vector-&gt;bytevector vector</var>)<var><a name="index-vector_002d_003ebytevector-383"></a></var><br>
    128 <blockquote><p>These applicatives convert between bytevectors and vectors.  If a
    129 vector containing objects other than bytes (exact integers between 0
    130 and 255 inclusive) is passed to <code>vector-&gt;bytevector</code>, an error is
    131 signaled.  The objects returned by these applicatives are always
    132 mutable. 
    133 </p></blockquote></div>
    134 
    135 <div class="defun">
    136 &mdash; Applicative: <b>bytevector-copy!</b> (<var>bytevector-copy! bytevector1 bytevector2</var>)<var><a name="index-bytevector_002dcopy_0021-384"></a></var><br>
    137 <blockquote><p>bytevector2 should have a length greater than or equal to that of
    138 bytevector1.
    139 
    140         <p>Copies the bytes in bytevector1 to the corresponding positions in
    141 bytevector2.  If bytevector2 is immutable, an error is signaled.  The
    142 result returned by <code>bytevector-copy!</code> is inert. 
    143 </p></blockquote></div>
    144 
    145 <div class="defun">
    146 &mdash; Applicative: <b>bytevector-copy-partial</b> (<var>bytevector-copy-partial bytevector k1 k2</var>)<var><a name="index-bytevector_002dcopy_002dpartial-385"></a></var><br>
    147 <blockquote><p>Both <code>k1</code> &amp; <code>k2</code> should be valid indexes in
    148 <code>bytevector</code>.  Also it should be the case that <code>k1 &lt;= k2</code>.
    149 
    150         <p>Applicative <code>bytevector-copy-partial</code> constructs and returns a
    151 new mutable bytevector with length <code>k2 - k1</code>, with the bytes from
    152 <code>bytevector</code>, starting at index <code>k1</code> (inclusive) and ending
    153 at index <code>k2</code> (exclusive). 
    154 </p></blockquote></div>
    155 
    156 <div class="defun">
    157 &mdash; Applicative: <b>bytevector-copy-partial!</b> (<var>bytevector-copy-partial! bytevector1 k1 k2 bytevector2 k3</var>)<var><a name="index-bytevector_002dcopy_002dpartial_0021-386"></a></var><br>
    158 <blockquote><p>Both <code>k1</code> &amp; <code>k2-1</code> should be valid indexes in
    159 <code>bytevector1</code>.  Also it should be the case that <code>k1 &lt;= k2</code>. 
    160 Both <code>k3</code> &amp; <code>k3 + (k2-k1) - 1</code> should be valid indexes in
    161 <code>bytevector2</code>.
    162 
    163         <p>Applicative <code>bytevector-copy-partial!</code> copies bytes k1
    164 (inclusive) through k2 (exclusive) from <code>bytevector1</code> to the
    165 <code>k2-k1</code> positions in <code>bytevector2</code> starting at <code>k3</code>. 
    166 If <code>bytevector2</code> is an immutable bytevector, an error is
    167 signaled.  The result returned by <code>bytevector-copy-partial!</code> is
    168 inert. 
    169 </p></blockquote></div>
    170 
    171 <div class="defun">
    172 &mdash; Applicative: <b>bytevector-fill!</b> (<var>bytevector-fill! bytevector u8</var>)<var><a name="index-bytevector_002dfill_0021-387"></a></var><br>
    173 <blockquote><p>Applicative <code>bytevector-fill!</code> replaces all the bytes in
    174 <code>bytevector</code> with byte <code>u8</code>.  If <code>bytevector</code> is an
    175 immutable bytevector, an error is signaled.  The result
    176 returned by <code>bytevector-fill!</code> is inert. 
    177 </p></blockquote></div>
    178 
    179 <div class="defun">
    180 &mdash; Applicative: <b>bytevector-&gt;immutable-bytevector</b> (<var>bytevector-&gt;immutable-bytevector bytevector</var>)<var><a name="index-bytevector_002d_003eimmutable_002dbytevector-388"></a></var><br>
    181 <blockquote><p>Applicative <code>bytevector-&gt;immutable-bytevector</code> constructs and
    182 returns a new immutable bytevector with the same length and bytes as
    183 <code>bytevector</code>. 
    184 </p></blockquote></div>
    185 
    186 <!-- *-texinfo-*- -->
    187    </body></html>
    188