factor/basis/math/ranges/ranges-docs.factor

29 lines
1.4 KiB
Factor
Raw Normal View History

2008-08-13 15:19:58 -04:00
USING: help.syntax help.markup arrays sequences ;
2008-03-20 19:33:01 -04:00
IN: math.ranges
2009-04-06 04:00:46 -04:00
ARTICLE: "math.ranges" "Numeric ranges"
2008-08-13 15:19:58 -04:00
"A " { $emphasis "range" } " is a virtual sequence with real number elements "
2008-09-27 12:37:46 -04:00
"ranging from " { $emphasis "a" } " to " { $emphasis "b" } " by " { $emphasis "step" } ". Ascending as well as descending ranges are supported."
2008-08-13 15:19:58 -04:00
$nl
"The class of ranges:"
{ $subsections range }
2008-08-13 15:19:58 -04:00
"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:"
{ $subsections
[a,b]
(a,b]
[a,b)
(a,b)
[0,b]
[1,b]
[0,b)
}
2008-08-13 15:19:58 -04:00
"Creating general ranges:"
{ $subsections <range> }
2008-08-13 15:19:58 -04:00
"Ranges are most frequently used with sequence combinators as a means of iterating over integers. For example,"
2008-09-27 12:37:46 -04:00
{ $code "3 10 [a,b] [ sqrt ] map" }
"Computing the factorial of 100 with a descending range:"
{ $code "100 1 [a,b] product" }
"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! } "." ;
2008-08-13 15:19:58 -04:00
2009-05-25 22:25:56 -04:00
ABOUT: "math.ranges"