]> gitweb.factorcode.org Git - factor.git/blob - basis/math/ranges/ranges-docs.factor
e35adb10e55e7b0d16b7b2ff3165f7eb64f5b002
[factor.git] / basis / math / ranges / ranges-docs.factor
1 USING: help.syntax help.markup arrays sequences ;
2
3 IN: math.ranges
4
5 ARTICLE: "math.ranges" "Numeric ranges"
6 "A " { $emphasis "range" } " is a virtual sequence with real number elements "
7 "ranging from " { $emphasis "a" } " to " { $emphasis "b" } " by " { $emphasis "step" } ". Ascending as well as descending ranges are supported."
8 $nl
9 "The class of ranges:"
10 { $subsection range }
11 "Creating ranges with integer end-points. The standard mathematical convention is used, where " { $snippet "(" } " or " { $snippet ")" } " denotes that the end-point itself " { $emphasis "is not" } " part of the range; " { $snippet "[" } " or " { $snippet "]" } " denotes that the end-point " { $emphasis "is" } " part of the range:"
12 { $subsection [a,b] }
13 { $subsection (a,b] }
14 { $subsection [a,b) }
15 { $subsection (a,b) }
16 { $subsection [0,b] }
17 { $subsection [1,b] }
18 { $subsection [0,b) }
19 "Creating general ranges:"
20 { $subsection <range> }
21 "Ranges are most frequently used with sequence combinators as a means of iterating over integers. For example,"
22 { $code "3 10 [a,b] [ sqrt ] map" }
23 "Computing the factorial of 100 with a descending range:"
24 { $code "100 1 [a,b] product" }
25 "A range can be converted into a concrete sequence using a word such as " { $link >array } ". In most cases this is unnecessary since ranges implement the sequence protocol already. It is necessary if a mutable sequence is needed, for use with words such as " { $link set-nth } " or " { $link change-each } "." ;
26   
27 ABOUT: "math.ranges"