Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for [[/eggref/5/dyn-vector|the CHICKEN 5 version of this egg]], if it exists. If it does not exist, there may be equivalent functionality provided by another egg; have a look at the [[https://wiki.call-cc.org/chicken-projects/egg-index-5.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. [[tags:egg]] == dyn-vector Dynamic (dense) vectors based on SRFI-43. [[toc:]] == Usage (require-extension dyn-vector) == Documentation The dyn-vector library is an implementation of a dynamically-growing vector, based on [[http://srfi.schemers.org/srfi-43/|SRFI-43]]. An attempt to set the {{i}}'th element of a dynvector of underlying size n causes the dynvector to grow to size {{2n}}, {{i+1}}, or {{16}}, whichever is greatest. The semantics of this library follow SRFI-43 closely, with the exception of the following procedures: <procedure>dynvector-ref vect i</procedure> If the index {{i}} is greater than the current size of the vector, this procedure returns the default value specified when the dynamic vector was created. <procedure>dynvector-set! vect i e</procedure> If the index {{i}} is greater than the current size of the vector, the vector size is increased to {{max(2*N,i+1)}} and the new element is then inserted in the vector. <procedure>dynvector-clear! vect n</procedure> This procedure removes all elements from the dynamic vector, and sets the size of the vector to {{n}}. <procedure>dynvector-extend! vect n</procedure> This procedure explicitly resizes the dynamic vector to the specified size. <procedure>dynvector-tabulate f len [dflt]</procedure> If the optional argument {{dflt}} is specified, it is used as default value, otherwise the first element in the vector is used as default value. <procedure>list->dynvector lst [dflt] -> dynvector</procedure> If the optional argument {{dflt}} is specified, it is used as default value, otherwise the first element in the list is used as default value. === Procedures <procedure>dynvector? x -> boolean</procedure> Returns {{#t}} if {{x}} is a dynamic vector, {{#f}} otherwise. <procedure>dynvector-tabulate f len [dflt]</procedure> Creates a new dynamic vector of length {{len}} and iterates across each index, applying f at each iteration to the current index; if the optional argument {{dflt}} is specified, it is used as default value, otherwise the first element in the vector is used as default value. <procedure>list->dynvector lst [dflt] -> dynvector</procedure> Creates a dynamic vector with the elements of the given list; if the optional argument {{dflt}} is specified, it is used as default value, otherwise the first element in the vector is used as default value. <procedure>dynvector elem ... -> dynvector</procedure> Creates a dynamic vector with the given elements; the default value is {{#f}}. <procedure>make-dynvector n default -> dynvector</procedure> Creates a dynamic vector of length {{n}} and fills it with value {{default}}. <procedure>dynvector-clear! x n -> unspecified</procedure> Removes all elements from the given dynamic vector, and sets the size of the vector to {{n}}. <procedure>dynvector-length x -> integer</procedure> Returns the length of the given dynamic vector. <procedure>dynvector-ref x i -> value</procedure> Returns the element at index {{i}}of the given dynamic vector{{x}}. <procedure>dynvector-set! x i e -> unspecified</procedure> Updates the element at index {{i}}of the given dynamic vector{{x}}; if the index {{i}} is greater than the current size of the vector, the vector size is increased to {{max(2*N,i+1)}} and the new element is then inserted in the vector. <procedure>dynvector-expand! x n -> unspecified</procedure> Expands the size of the dynamic vector to the given size {{n}}. <procedure>dynvector-for-each f x1 ... -> unspecified</procedure> Dynamic vector iterator: applies {{f}}to each index in the range {{[0, k)}}, where {{k}} is the length of the smallest dynamic vector argument passed, and the respective list of parallel elements from {{x1}} ... at that index. <procedure>dynvector-map f x1 ... -> dynvector</procedure> Constructs a new dynamic vector of the shortest size of the given dynamic vector; each element at index {{i}} of the new dynamic vector is mapped from the old vectors by {{f i (dynvector-ref x1 i) ...}}. <procedure>dynvector-copy x -> dynvector</procedure> Creates a copy of the given dynamic vector. <procedure>dynvector-fold f initial x1 ... -> state</procedure> Left-to-right dynamic vector iterator with state. {{f}} is iterated over each index in all of the vectors, stopping at the end of the shortest; {{f}} is applied as {{(f i state (dynvector-ref x1 i) ...)}} where state is the current state value, which begins with {{initial}} and becomes whatever {{f}}returns at the respective iteration; {{i}} is the current index. <procedure>dynvector-fold-right f initial x1 ... -> state</procedure> Right-to-left dynamic vector iterator with state. {{f}} is iterated over each index in all of the vectors, stopping at the end of the shortest; {{f}} is applied as {{(f i state (dynvector-ref x1 i) ...)}} where state is the current state value, which begins with {{initial}} and becomes whatever {{f}}returns at the respective iteration; {{i}} is the current index. <procedure>dynvector-index pred? x1 ... -> integer or #f</procedure> Finds and returns the index of the first elements in {{x1 ...}} that satisfy {{pred?}}; if no matching element is found by the end of the shortest vector, {{#f}} is returned. <procedure>dynvector-any pred? x1 ... -> value or #f</procedure> Finds the first set of elements in {{x1 ... }}for which {{pred?}} returns a true value. If such a parallel set of elements exists, this procedure returns the value that {{pred?}}returned for that set of elements. <procedure>dynvector-every pred? x1 ... -> value or #f</procedure> If, for every index {{i}} between 0 and the length of the shortest vector argument, the set of elements {{(dynvector-ref x1 i) ...}} satisfies {{pred?}}, this procedure returns the value that {{pred?}}returned for the last set of elements. <procedure>dynvector->list x1 -> list</procedure> Returns a list containing all the elements in the given dynamic vector. == Examples csi> (require-extension dyn-vector) csi> (define dv (make-dynvector 1 0)) csi> (dynvector-ref dv 6) 0 csi> (dynvector-set! dv 6 18) csi> (dynvector-ref dv 6) 18 csi> (define dv2 (list->dynvector '(1 2 3))) csi> dv2 #(dynvector 1 2 3) csi> (dynvector-ref dv2 4) 1 csi> (dynvector-clear! dv2 5) csi> (dynvector-for-each (lambda (i x) (print i " = " x)) dv2) 0 = 1 1 = 1 2 = 1 3 = 1 4 = 1 csi> (dynvector-map (lambda (i x) (+ x i)) dv2) #(dynvector 1 2 3 4 5) csi> (dynvector-fold (lambda (i state v) (+ state v)) 0 dv2) 5 == About this egg === Author [[/users/ivan-raikov|Ivan Raikov]] === Version history ; 1.13 : Bug fixes for zero-sized vectors; added procedure dynvector [thanks to Lewis Campbell] ; 1.12 : License change to LGPL-3 ; 1.11 : Converted documentation to wiki format ; 1.9 : Ported to Chicken 4 ; 1.8 : Build script updated for better cross-platform compatibility ; 1.7 : eggdoc documentation fix ; 1.6 : License upgrade to GPL v3 ; 1.5 : Minor updates to the setup script ; 1.4 : Bug fix in the setup script ; 1.3 : Added a clarification of how the vector grows [thanks to John Cowan] ; 1.2 : Bug fix to handle zero-length initial base vector ; 1.1 : Added optional dflt argument to list->dynvector and dynvector->tabulate ; 1.0 : Initial release === License Parts of this documentation are taken from SRFI-43. The rest was created by Ivan Raikov. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A full copy of the Lesser GPL license can be found at <http://www.gnu.org/licenses/>.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you subtract 0 from 5?