: sort-loop ( merge quot -- )
[ 2 [ over seq>> length over > ] ] dip
[ [ 1 shift 2dup ] dip sort-pass ] curry
- [ ] while 2drop ; inline
+ while 2drop ; inline
: each-pair ( seq quot -- )
[ [ length 1+ 2/ ] keep ] dip
[ drop nip nth ] dip push
] [
[
- [ tuck [ nth-unsafe ] 2bi@ 2dup ] dip call +gt+ eq?
+ [ [ nth-unsafe ] curry bi@ 2dup ] dip call +gt+ eq?
[ swap ] when
- ] dip tuck [ push ] 2bi@
+ ] dip [ push ] curry bi@
] if ; inline
: sort-pairs ( merge quot -- )