Handbook
Glossary
insert ( ... seq quot: ( ... elt -- ... elt' ) n -- ... )
Vocabulary
sorting
.
insertion
.
private
Inputs
seq
an
object
quot
a
quotation
with stack effect
( ... elt -- ... elt' )
n
an
object
Outputs
None
Definition
USING:
kernel
math
sequences.private
;
IN:
sorting.insertion.private
::
insert
( ... seq quot: ( ... elt -- ... elt' ) n -- ... )
n
zero?
[
n n 1
-
[
seq
nth-unsafe
]
bi@
2dup
[
quot
call
]
bi@
>=
[
2drop
]
[
n 1
-
n
[
seq
set-nth-unsafe
]
bi-curry@
bi*
seq quot n 1
-
insert
]
if
]
unless
;
inline
recursive