]> gitweb.factorcode.org Git - factor.git/blob - core/math/ranges/ranges-docs.factor
ui: trim even more using lists
[factor.git] / core / 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 { $subsections 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 { $subsections
12     [a..b]
13     (a..b]
14     [a..b)
15     (a..b)
16     [0..b]
17     [1..b]
18     [0..b)
19 }
20 "Creating general ranges:"
21 { $subsections <range> }
22 "Ranges are most frequently used with sequence combinators as a means of iterating over integers. For example,"
23 { $code "3 10 [a..b] [ sqrt ] map" }
24 "Computing the factorial of 100 with a descending range:"
25 { $code "100 1 [a..b] product" }
26 "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 map! } "." ;
27
28 ABOUT: "math.ranges"