Handbook
Glossary
kth-object-impl ( seq k nth-quot exchange-quot quot: ( x y -- ? ) -- elt )
Vocabulary
math
.
statistics
.
private
Inputs
seq
an
object
k
an
object
nth-quot
an
object
exchange-quot
an
object
quot
a
quotation
with stack effect
( x y -- ? )
Outputs
elt
an
object
Definition
USING:
kernel
math
sequences
sequences.private
;
IN:
math.statistics.private
::
kth-object-impl
( seq k nth-quot exchange-quot quot: ( x y -- ? ) -- elt )
k seq
bounds-check
2drop
0
:>
i! 0
:>
j! 0
:>
l! 0
:>
x! seq
length
1
-
:>
m!
[
l m
<
]
[
k seq
nth-unsafe
x! l i! m j!
[
i j
<=
]
[
[
i seq nth-quot
call
x quot
call
]
[
i 1
+
i!
]
while
[
x j seq nth-quot
call
quot
call
]
[
j 1
-
j!
]
while
i j
<=
[
i j seq exchange-quot
call
i 1
+
i! j 1
-
j!
]
when
]
do
while
j k
<
[
i l!
]
when
k i
<
[
j m!
]
when
]
while
k seq
nth-unsafe
;
inline