Handbook
Glossary
(binary-reduce) ( seq start quot: ( elt1 elt2 -- newelt ) from length -- value )
Vocabulary
sequences
.
private
Inputs
seq
an
object
start
an
object
quot
a
quotation
with stack effect
( elt1 elt2 -- newelt )
from
an
object
length
an
object
Outputs
value
an
object
Definition
USING:
kernel
math
;
IN:
sequences.private
:
(binary-reduce)
( seq start quot: ( elt1 elt2 -- newelt ) from length -- value )
dup
4
<
[
integer>fixnum
{
[
2drop
nip
]
[
2nip
swap
nth-unsafe
]
[
-rot
[
drop
swap
nth2-unsafe
]
dip
call
]
[
-rot
[
drop
swap
nth3-unsafe
]
dip
bi@
]
}
dispatch
]
[
[
2/
]
[
over
-
]
bi
[
2dup
+
]
dip
[
(binary-reduce)
]
[
2curry
]
curry
2bi@
pick
[
3bi
]
dip
call
]
if
;
inline
recursive