Handbook
Glossary
range
Factor handbook
»
The language
»
Collections
»
Sequence operations
»
Numeric ranges
Next:
[a..b] ( a b -- range )
Vocabulary
ranges
Definition
USING:
math
;
IN:
ranges
TUPLE:
range
{
from
number
read-only
initial:
0
}
{
length
integer
read-only
initial:
0
}
{
step
number
read-only
initial:
0
}
;
Methods
USING:
kernel
ranges
sets
;
M:
range
all-unique?
drop
t
;
USING:
accessors
ranges
sets
;
M:
range
cardinality
length>>
;
USING:
kernel
ranges
sets
;
M:
range
duplicates
drop
f
;
USING:
classes.tuple
kernel
ranges
;
M:
range
hashcode*
tuple-hashcode
;
USING:
kernel
math
math.order
ranges
ranges.private
sets
;
M:
range
in?
over
number?
[
>forward-range<
[
3dup
between?
]
dip
swap
[
nip
3dup
[
-
]
dip
/i
*
+
=
]
[
4drop
f
]
if
]
[
2drop
f
]
if
;
USING:
generic
kernel
ranges
ranges.private
sets
;
M:
range
intersect
over
range?
[
intersect-range
]
[
M\
range
intersect
(call-next-method)
]
if
;
USING:
accessors
generic
kernel
math
ranges
ranges.private
sets
;
M:
range
intersects?
over
range?
[
intersect-range
length>>
zero?
not
]
[
M\
range
intersects?
(call-next-method)
]
if
;
USING:
accessors
ranges
sequences
;
M:
range
length
length>>
;
inline
USING:
accessors
kernel
math
ranges
sequences
;
M:
range
maximum
dup
step>>
0
>
[
last
]
[
first
]
if
;
USING:
arrays
ranges
sets
;
M:
range
members
>array
;
USING:
accessors
kernel
math
ranges
sequences
;
M:
range
minimum
dup
step>>
0
>
[
first
]
[
last
]
if
;
USING:
kernel
math.vectors
ranges
;
M:
range
n*v
swap
v*n
;
USING:
kernel
math.vectors
ranges
;
M:
range
n+v
swap
v+n
;
USING:
kernel
math
math.vectors
ranges
ranges.private
;
M:
range
n-v
>range<
roll
[
swap
-
]
curry
[
bi@
]
curry
dip
neg
<range>
;
USING:
accessors
kernel
math
ranges
sequences.private
;
M:
range
nth-unsafe
[
step>>
*
]
keep
from>>
+
;
inline
USING:
generic
kernel
ranges
ranges.private
sequences
sets
;
M:
range
set=
over
range?
[
[
[
empty-range
]
[
forward-range
]
if-empty
]
bi@
=
]
[
M\
range
set=
(call-next-method)
]
if
;
USING:
generic
kernel
ranges
ranges.private
sequences
sets
;
M:
range
subset?
over
range?
[
over
empty?
[
2drop
t
]
[
dupd
intersect-range
=
]
if
]
[
M\
range
subset?
(call-next-method)
]
if
;
USING:
kernel
math
ranges
sequences
sequences.private
;
M:
range
sum
dup
length
[
drop
0
]
[
swap
[
first-unsafe
]
[
last-unsafe
]
bi
+
*
2
/
]
if-zero
;
USING:
accessors
combinators.short-circuit
generic
kernel
math
math.statistics
ranges
sequences
;
M:
range
sum-of-cubes
dup
{
[
step>>
1
=
]
[
from>>
integer?
]
}
1&&
[
[
from>>
]
[
length>>
]
bi
dupd
+
[
<iota>
sum-of-cubes
]
bi@
swap
-
]
[
M\
range
sum-of-cubes
(call-next-method)
]
if
;
USING:
accessors
combinators.short-circuit
generic
kernel
math
math.statistics
ranges
sequences
;
M:
range
sum-of-quads
dup
{
[
step>>
1
=
]
[
from>>
integer?
]
}
1&&
[
[
from>>
]
[
length>>
]
bi
dupd
+
[
<iota>
sum-of-quads
]
bi@
swap
-
]
[
M\
range
sum-of-quads
(call-next-method)
]
if
;
USING:
accessors
combinators.short-circuit
generic
kernel
math
math.statistics
ranges
sequences
;
M:
range
sum-of-squares
dup
{
[
step>>
1
=
]
[
from>>
integer?
]
}
1&&
[
[
from>>
]
[
length>>
]
bi
dupd
+
[
<iota>
sum-of-squares
]
bi@
swap
-
]
[
M\
range
sum-of-squares
(call-next-method)
]
if
;
USING:
kernel
math
math.vectors
ranges
ranges.private
;
M:
range
v*n
[
>range<
]
dip
[
*
]
curry
tri@
<range>
;
USING:
accessors
generic
kernel
math
math.order
math.vectors
ranges
;
M:
range
v+
over
range?
[
[
[
from>>
]
bi@
+
]
[
[
length>>
]
bi@
min
]
[
[
step>>
]
bi@
+
]
2tri
\
range
boa
]
[
M\
range
v+
(call-next-method)
]
if
;
USING:
kernel
math
math.vectors
ranges
ranges.private
;
M:
range
v+n
[
>range<
]
dip
[
+
]
curry
[
bi@
]
curry
dip
<range>
;
USING:
kernel
math
math.vectors
ranges
ranges.private
;
M:
range
v-
>range<
[
neg
]
tri@
<range>
v+
;
USING:
math
math.vectors
ranges
;
M:
range
v-n
neg
v+n
;
USING:
math
math.vectors
ranges
;
M:
range
v/n
recip
v*n
;
USING:
generic
kernel
math.vectors
ranges
;
M:
range
vavg
over
range?
[
v+
2
v/n
]
[
M\
range
vavg
(call-next-method)
]
if
;
USING:
kernel
math
math.vectors
ranges
ranges.private
;
M:
range
vneg
>range<
[
neg
]
tri@
<range>
;