]> gitweb.factorcode.org Git - factor.git/blob - basis/math/ranges/ranges-docs.factor
Resolved merge.
[factor.git] / basis / math / ranges / ranges-docs.factor
1 USING: help.syntax help.markup arrays sequences ;
2 IN: math.ranges
3
4 ARTICLE: "math.ranges" "Numeric ranges"
5 "A " { $emphasis "range" } " is a virtual sequence with real number elements "
6 "ranging from " { $emphasis "a" } " to " { $emphasis "b" } " by " { $emphasis "step" } ". Ascending as well as descending ranges are supported."
7 $nl
8 "The class of ranges:"
9 { $subsection range }
10 "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:"
11 { $subsection [a,b] }
12 { $subsection (a,b] }
13 { $subsection [a,b) }
14 { $subsection (a,b) }
15 { $subsection [0,b] }
16 { $subsection [1,b] }
17 { $subsection [0,b) }
18 "Creating general ranges:"
19 { $subsection <range> }
20 "Ranges are most frequently used with sequence combinators as a means of iterating over integers. For example,"
21 { $code "3 10 [a,b] [ sqrt ] map" }
22 "Computing the factorial of 100 with a descending range:"
23 { $code "100 1 [a,b] product" }
24 "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 } "." ;
25   
26 ABOUT: "math.ranges"