]> gitweb.factorcode.org Git - factor.git/blob - basis/tuple-arrays/tuple-arrays-docs.factor
Solution to Project Euler problem 65
[factor.git] / basis / tuple-arrays / tuple-arrays-docs.factor
1 IN: tuple-arrays
2 USING: help.markup help.syntax sequences ;
3
4 HELP: TUPLE-ARRAY:
5 { $syntax "TUPLE-ARRAY: class" }
6 { $description "Generates a new data type in the current vocabulary named " { $snippet { $emphasis "class" } "-array" } " for holding instances of " { $snippet "class" } ", which must be a tuple class word. Together with the class itself, this also generates words named " { $snippet "<" { $emphasis "class" } "-array>" } " and " { $snippet ">" { $emphasis "class" } "-array" } ", for creating new instances of this tuple array type." } ;
7
8 ARTICLE: "tuple-arrays" "Tuple arrays"
9 "The " { $vocab-link "tuple-arrays" } " vocabulary implements space-efficient unboxed tuple arrays. Whereas an ordinary array of tuples would consist of pointers to heap-allocated objects, a tuple array stores its elements inline. Calling " { $link nth } " copies an element into a new tuple, and calling " { $link set-nth } " copies an existing tuple's slots into an array."
10 $nl
11 "Since value semantics differ from reference semantics, it is best to use tuple arrays with tuples where all slots are declared " { $link read-only } "."
12 $nl
13 "Tuple arrays should not be used with inheritance; storing an instance of a subclass in a tuple array will slice off the subclass slots, and getting the same value out again will yield an instance of the superclass. Also, tuple arrays do not get updated if tuples are redefined to add or remove slots, so caution should be exercised when doing interactive development on code that uses tuple arrays."
14 { $subsection POSTPONE: TUPLE-ARRAY: }
15 "An example:"
16 { $example
17   "USE: tuple-arrays"
18   "IN: scratchpad"
19   "TUPLE: point x y ;"
20   "TUPLE-ARRAY: point"
21   "{ T{ point f 1 2 } T{ point f 1 3 } T{ point f 2 3 } } >point-array first short."
22   "T{ point f 1 2 }"
23 } ;
24
25 ABOUT: "tuple-arrays"