]> gitweb.factorcode.org Git - factor.git/blob - core/arrays/arrays-docs.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / core / arrays / arrays-docs.factor
1 USING: help.markup help.syntax
2 kernel kernel.private prettyprint sequences.private sequences ;
3 IN: arrays
4
5 ARTICLE: "arrays-unsafe" "Unsafe array operations"
6 "These two words are used internally by the Factor implementation. User code should never need to call them; instead use " { $link nth } " and " { $link set-nth } "."
7 { $subsection array-nth }
8 { $subsection set-array-nth } ;
9
10 ARTICLE: "arrays" "Arrays"
11 "The " { $vocab-link "arrays" } " vocabulary implements fixed-size mutable sequences which support the " { $link "sequence-protocol" } "."
12 $nl
13 "The " { $vocab-link "arrays" } " vocabulary only includes words for creating new arrays. To access and modify array elements, use " { $link "sequences" } " in the " { $vocab-link "sequences" } " vocabulary."
14 $nl
15 "Array literal syntax is documented in " { $link "syntax-arrays" } ". Resizable arrays also exist and are known as " { $link "vectors" } "."
16 $nl
17 "Arrays form a class of objects:"
18 { $subsection array }
19 { $subsection array? }
20 "Creating new arrays:"
21 { $subsection >array }
22 { $subsection <array> }
23 "Creating an array from several elements on the stack:"
24 { $subsection 1array }
25 { $subsection 2array }
26 { $subsection 3array }
27 { $subsection 4array }
28 "The class of two-element arrays:"
29 { $subsection pair }
30 "Arrays can be accessed without bounds checks in a pointer unsafe way."
31 { $subsection "arrays-unsafe" } ;
32
33 ABOUT: "arrays"
34
35 HELP: array
36 { $description "The class of fixed-length arrays. See " { $link "syntax-arrays" } " for syntax and " { $link "arrays" } " for general information." } ;
37
38 HELP: <array> ( n elt -- array )
39 { $values { "n" "a non-negative integer" } { "elt" "an initial element" } { "array" "a new array" } }
40 { $description "Creates a new array with the given length and all elements initially set to " { $snippet "elt" } "." } ;
41
42 HELP: >array
43 { $values { "seq" "a sequence" } { "array" array } }
44 { $description "Outputs a freshly-allocated array with the same elements as a given sequence." } ;
45
46 HELP: 1array
47 { $values { "x" object } { "array" array } }
48 { $description "Create a new array with one element." } ;
49
50 { 1array 2array 3array 4array } related-words
51
52 HELP: 2array
53 { $values { "x" object } { "y" object } { "array" array } }
54 { $description "Create a new array with two elements, with " { $snippet "x" } " appearing first." } ;
55
56 HELP: 3array
57 { $values { "x" object } { "y" object } { "z" object } { "array" array } }
58 { $description "Create a new array with three elements, with " { $snippet "x" } " appearing first." } ;
59
60 HELP: 4array
61 { $values { "w" object } { "x" object } { "y" object } { "z" object } { "array" array } }
62 { $description "Create a new array with four elements, with " { $snippet "w" } " appearing first." } ;
63
64 HELP: resize-array ( n array -- newarray )
65 { $values { "n" "a non-negative integer" } { "array" array } { "newarray" "a new array" } }
66 { $description "Creates a new array of " { $snippet "n" } " elements. The contents of the existing array are copied into the new array; if the new array is shorter, only an initial segment is copied, and if the new array is longer the remaining space is filled in with "{ $link f } "." } ;
67
68 HELP: pair
69 { $class-description "The class of two-element arrays, known as pairs." } ;