klisp

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

Vectors.html (10393B)


      1 <html lang="en">
      2 <head>
      3 <title>Vectors - 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="Ports.html#Ports" title="Ports">
      9 <link rel="next" href="Bytevectors.html#Bytevectors" title="Bytevectors">
     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="Vectors"></a>
     28 <p>
     29 Next:&nbsp;<a rel="next" accesskey="n" href="Bytevectors.html#Bytevectors">Bytevectors</a>,
     30 Previous:&nbsp;<a rel="previous" accesskey="p" href="Ports.html#Ports">Ports</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">18 Vectors</h2>
     37 
     38 <p><a name="index-Vectors-349"></a>
     39 A vector is an object that contains a sequence of arbitrary klisp
     40 objects.  A vector has a length that is fixed at creation time, and as
     41 many objects, indexed from <code>0</code> to <code>length-1</code>.  Compared to
     42 lists, klisp vectors use less size and have constant access time for
     43 any element.
     44 
     45    <p>Vectors may be mutable or immutable.  If an attempt is made to mutate
     46 an immutable vector, an error is signaled.  Two immutable vectors are
     47 &ldquo;eq?&rdquo; iff they are &ldquo;equal?&rdquo;.  Two mutable vectors are &ldquo;eq?&rdquo; if
     48 they were created by the same constructor call.  Two mutable vectors
     49 are &ldquo;equal?&rdquo; iff they have the same length and have &ldquo;equal?&rdquo;
     50 objects in each position.  As is the case for lists, in order to
     51 handle possibly cyclic structures, the &ldquo;equal?&rdquo; algorithm considers
     52 vectors as FSMs where it position is a state change.  There is only one
     53 empty vector (that is, a vector of length 0) and that vector is
     54 immutable.  The vector type is encapsulated.
     55 
     56    <p>SOURCE NOTE: The report doesn't currently include vectors. They are
     57 taken from r7rs scheme.
     58 
     59 <div class="defun">
     60 &mdash; Applicative: <b>vector?</b> (<var>vector? . objects</var>)<var><a name="index-vector_003f-350"></a></var><br>
     61 <blockquote><p>The primitive type predicate for type vector.  <code>vector?</code>
     62 returns true iff all the objects in <code>objects</code> are of type
     63 vector. 
     64 </p></blockquote></div>
     65 
     66 <div class="defun">
     67 &mdash; Applicative: <b>immutable-vector?</b> (<var>immutable-vector? objects</var>)<var><a name="index-immutable_002dvector_003f-351"></a></var><br>
     68 &mdash; Applicative: <b>mutable-vector?</b> (<var>mutable-vector? objects</var>)<var><a name="index-mutable_002dvector_003f-352"></a></var><br>
     69 <blockquote><p>The primitive type predicates for types immutable vector and mutable
     70 vector.  These return true iff all the objects in <code>objects</code> are of
     71 type immutable vector or mutable vector respectively. 
     72 </p></blockquote></div>
     73 
     74 <div class="defun">
     75 &mdash; Applicative: <b>make-vector</b> (<var>make-vector k </var>[<var>obj</var>])<var><a name="index-make_002dvector-353"></a></var><br>
     76 <blockquote><p>Applicative <code>make-vector</code> constructs and returns a new mutable
     77 vector of length <code>k</code>.  If <code>obj</code> is specified, then all
     78 objects in the returned vector are <code>obj</code>, otherwise the
     79 content of the vector is unspecified. 
     80 </p></blockquote></div>
     81 
     82 <div class="defun">
     83 &mdash; Applicative: <b>vector-length</b> (<var>vector-length vector</var>)<var><a name="index-vector_002dlength-354"></a></var><br>
     84 <blockquote><p>Applicative <code>vector-length</code> returns the length of
     85 <code>vector</code>. 
     86 </p></blockquote></div>
     87 
     88 <div class="defun">
     89 &mdash; Applicative: <b>vector-ref</b> (<var>vector-ref vector k</var>)<var><a name="index-vector_002dref-355"></a></var><br>
     90 <blockquote><p>Applicative <code>vector-ref</code> returns the object of <code>vector</code> at
     91 position <code>k</code>.  If <code>k</code> is out of bounds (i.e. less than
     92 <code>0</code> or greater or equal than <code>(vector-length vector)</code>) an
     93 error is signaled. 
     94 </p></blockquote></div>
     95 
     96 <div class="defun">
     97 &mdash; Applicative: <b>vector-set!</b> (<var>vector-set! vector k obj</var>)<var><a name="index-vector_002dset_0021-356"></a></var><br>
     98 <blockquote><p>Applicative <code>vector-set!</code> replaces the object with index <code>k</code>
     99 in <code>vector</code> with object <code>obj</code>.  If <code>k</code> is out of
    100 bounds, or <code>vector</code> is immutable, an error is signaled. The
    101 result returned by <code>vector-set!</code> is inert. 
    102 </p></blockquote></div>
    103 
    104 <div class="defun">
    105 &mdash; Applicative: <b>vector</b> (<var>vector . objs</var>)<var><a name="index-vector-357"></a></var><br>
    106 <blockquote><p>Applicative <code>vector</code> contructs and return a new mutable vector
    107 composed of the object arguments. 
    108 </p></blockquote></div>
    109 
    110 <div class="defun">
    111 &mdash; Applicative: <b>vector-&gt;list</b> (<var>vector-&gt;list vector</var>)<var><a name="index-vector_002d_003elist-358"></a></var><br>
    112 &mdash; Applicative: <b>list-&gt;vector</b> (<var>list-&gt;vector objs</var>)<var><a name="index-list_002d_003evector-359"></a></var><br>
    113 <blockquote><p>These applicatives convert between vectors and lists.  The objects
    114 returned by these applicatives are always mutable. 
    115 </p></blockquote></div>
    116 
    117 <div class="defun">
    118 &mdash; Applicative: <b>vector-copy</b> (<var>vector-copy vector</var>)<var><a name="index-vector_002dcopy-360"></a></var><br>
    119 <blockquote><p>Applicative <code>vector-copy</code> constructs and returns a new mutable
    120 vector with the same length and objects as <code>vector</code>. 
    121 </p></blockquote></div>
    122 
    123 <div class="defun">
    124 &mdash; Applicative: <b>vector-&gt;bytevector</b> (<var>vector-&gt;bytevector vector</var>)<var><a name="index-vector_002d_003ebytevector-361"></a></var><br>
    125 &mdash; Applicative: <b>bytevector-&gt;vector</b> (<var>bytevector-&gt;vector bytevector</var>)<var><a name="index-bytevector_002d_003evector-362"></a></var><br>
    126 <blockquote><p>These applicatives convert between vectors and bytevectors.  If a
    127 vector containing objects other than exact integers between 0 and 255
    128 inclusive are passed to <code>vector-&gt;bytevector</code>, an error is
    129 signaled.  The objects returned by these applicatives are always
    130 mutable. 
    131 </p></blockquote></div>
    132 
    133 <div class="defun">
    134 &mdash; Applicative: <b>vector-&gt;string</b> (<var>vector-&gt;string vector</var>)<var><a name="index-vector_002d_003estring-363"></a></var><br>
    135 &mdash; Applicative: <b>string-&gt;vector</b> (<var>string-&gt;vector string</var>)<var><a name="index-string_002d_003evector-364"></a></var><br>
    136 <blockquote><p>These applicatives convert between vectors and strings.  If a vector
    137 containing objects other than characters is passed to
    138 <code>vector-&gt;string</code>, an error is signaled.  The objects returned by
    139 these applicatives are always mutable. 
    140 </p></blockquote></div>
    141 
    142 <div class="defun">
    143 &mdash; Applicative: <b>vector-copy!</b> (<var>vector-copy! vector1 vector2</var>)<var><a name="index-vector_002dcopy_0021-365"></a></var><br>
    144 <blockquote><p>vector2 should have a length greater than or equal to
    145 that of vector1.
    146 
    147         <p>Copies the values in vector1 to the corresponding positions in
    148 vector2.  If vector2 is immutable, an error is signaled.  The result
    149 returned by <code>vector-copy!</code> is inert. 
    150 </p></blockquote></div>
    151 
    152 <div class="defun">
    153 &mdash; Applicative: <b>vector-copy-partial</b> (<var>vector-copy-partial vector k1 k2</var>)<var><a name="index-vector_002dcopy_002dpartial-366"></a></var><br>
    154 <blockquote><p>Both <code>k1</code> &amp; <code>k2</code> should be valid indexes in
    155 <code>vector</code>.  Also it should be the case that <code>k1 &lt;= k2</code>.
    156 
    157         <p>Applicative <code>vector-copy-partial</code> constructs and returns a new
    158 mutable vector with length <code>k2 - k1</code>, with the objects from
    159 <code>vector</code>, starting at index <code>k1</code> (inclusive) and ending at
    160 index <code>k2</code> (exclusive). 
    161 </p></blockquote></div>
    162 
    163 <div class="defun">
    164 &mdash; Applicative: <b>vector-copy-partial!</b> (<var>vector-copy-partial! vector1 k1 k2 vector2 k3</var>)<var><a name="index-vector_002dcopy_002dpartial_0021-367"></a></var><br>
    165 <blockquote><p>Both <code>k1</code> &amp; <code>k2-1</code> should be valid indexes in
    166 <code>vector1</code>.  Also it should be the case that <code>k1 &lt;= k2</code>. 
    167 Both <code>k3</code> &amp; <code>k3 + (k2-k1) - 1</code> should be valid indexes in
    168 <code>vector2</code>.
    169 
    170         <p>Applicative <code>vector-copy-partial!</code> copies objects k1 (inclusive)
    171 through k2 (exclusive) from <code>vector1</code> to the <code>k2-k1</code>
    172 positions in <code>vector2</code> starting at <code>k3</code>.  If <code>vector2</code>
    173 is an immutable vector, an error is signaled.  The result returned by
    174 <code>vector-copy-partial!</code> is inert. 
    175 </p></blockquote></div>
    176 
    177 <div class="defun">
    178 &mdash; Applicative: <b>vector-fill!</b> (<var>vector-fill! vector obj</var>)<var><a name="index-vector_002dfill_0021-368"></a></var><br>
    179 <blockquote><p>Applicative <code>vector-fill!</code> replaces all the objects in
    180 <code>vector</code> with object <code>obj</code>.  If <code>vector</code> is an
    181 immutable vector, an error is signaled.  The result
    182 returned by <code>vector-fill!</code> is inert. 
    183 </p></blockquote></div>
    184 
    185 <div class="defun">
    186 &mdash; Applicative: <b>vector-&gt;immutable-vector</b> (<var>vector-&gt;immutable-vector vector</var>)<var><a name="index-vector_002d_003eimmutable_002dvector-369"></a></var><br>
    187 <blockquote><p>Applicative <code>vector-&gt;immutable-vector</code> constructs and returns a
    188 new immutable vector with the same length and objects as
    189 <code>vector</code>. 
    190 </p></blockquote></div>
    191 
    192 <!-- *-texinfo-*- -->
    193    </body></html>
    194