Factor Documentation
|
Home
|
Glossary
|
Search
factorcode.org
sum ( seq -- n )
Vocabulary
sequences
Inputs and outputs
seq
a sequence of numbers
n
a number
Word description
Outputs the sum of all elements of
seq
. Outputs zero given an empty sequence.
Definition
IN:
sequences
GENERIC:
sum
( seq -- n )
Methods
USING:
math
sequences
sequences.cords
;
M:
cord
sum
[
sum
]
cord-both
+
;
inline
USING:
kernel
math
sequences
;
M:
object
sum
0
[
+
]
binary-reduce
;
inline
USING:
generic
kernel
math.vectors.simd
math.vectors.simd.intrinsics
math.vectors.simd.private
sequences
;
M:
simd-128
sum
dup
simd-rep
[
(simd-sum)
]
[
M\
simd-128
sum
(call-next-method)
]
v->x-op
;
inline