1 USING: help.markup help.syntax kernel sequences ;
4 ARTICLE: "vectors" "Vectors"
5 "The " { $vocab-link "vectors" } " vocabulary implements resizable mutable sequence which support the " { $link "sequence-protocol" } "."
7 "The " { $vocab-link "vectors" } " vocabulary only includes words for creating new vectors. To access and modify vector elements, use " { $link "sequences" } " in the " { $vocab-link "sequences" } " vocabulary."
9 "Vector literal syntax is documented in " { $link "syntax-vectors" } "."
11 "Vectors are intended to be used with " { $link "sequences-destructive" } ". Code that does not modify sequences in-place can use fixed-size arrays without loss of generality; see " { $link "arrays" } "."
13 "Vectors form a class of objects:"
18 "Creating new vectors:"
23 "Creating a vector from a single element:"
24 { $subsections 1vector }
25 "If you don't care about initial capacity, an elegant way to create a new vector is to write:"
26 { $code "V{ } clone" } ;
31 { $class-description "The class of resizable vectors. See " { $link "syntax-vectors" } " for syntax and " { $link "vectors" } " for general information." } ;
34 { $values { "n" "a positive integer specifying initial capacity" } { "vector" vector } }
35 { $description "Creates a new vector that can hold " { $snippet "n" } " elements before resizing." } ;
38 { $values { "seq" sequence } { "vector" vector } }
39 { $description "Outputs a freshly-allocated vector with the same elements as a given sequence." } ;
42 { $values { "x" object } { "vector" vector } }
43 { $description "Create a new vector with one element." } ;
46 { $values { "elt" object } { "seq/f" { $maybe "a resizable mutable sequence" } } { "seq" "a resizable mutable sequence" } }
47 { $description "If the given sequence is " { $link f } ", creates and outputs a new one-element vector holding " { $snippet "elt" } ". Otherwise, pushes " { $snippet "elt" } " onto the given sequence." }
48 { $errors "Throws an error if " { $snippet "seq" } " is not resizable, or if the type of " { $snippet "elt" } " is not permitted in " { $snippet "seq" } "." }
49 { $side-effects "seq" } ;