2 over to
1 over to
3 swap to
- natural-sort
+ sort
] unit-test
{ { 1 2 4 9 } } [
2dup from swap push
2dup from swap push
dupd from swap push
- natural-sort
+ sort
] unit-test
: compute-dom-children ( dom-parents -- dom-childrens )
H{ } clone [ '[ 2dup eq? [ 2drop ] [ _ push-at ] if ] assoc-each ] keep
- [ [ number>> ] sort-with ] assoc-map ;
+ [ [ number>> ] sort-by ] assoc-map ;
SYMBOLS: preorder maxpreorder ;
{ { 3 56 } } [
{ { 3 7 } { -1 56 } { -1 3 } } >min-heap [ -1 = ] heap-pop-while
- natural-sort
+ sort
] unit-test
] if ;
: sorted-successors ( bb -- seq )
- successors>> <reversed> [ loop-nesting-at ] sort-with ;
+ successors>> <reversed> [ loop-nesting-at ] sort-by ;
: process-block ( bb -- bbs )
dup visited get ?adjoin [ dup , sorted-successors ] [ drop { } ] if
M: ##phi coalesce-now
[ dst>> ] [ inputs>> values ] bi zip-scalar
- natural-sort t try-eliminate-copies ;
+ sort t try-eliminate-copies ;
GENERIC: coalesce-later ( insn -- )
! See https://factorcode.org/license.txt for BSD license.
USING: accessors arrays combinators combinators.short-circuit
compiler.cfg.dominance compiler.cfg.ssa.interference.live-ranges
-kernel locals math math.order sequences sorting.slots ;
+kernel locals math math.order sequences sorting.specification ;
IN: compiler.cfg.ssa.interference
TUPLE: vreg-info vreg value def-index bb pre-of color equal-anc-in equal-anc-out ;
! Merging lists of vregs sorted by dominance.
M: vreg-info <=> ( vreg1 vreg2 -- <=> )
- { { pre-of>> <=> } { def-index>> <=> } } compare-slots ;
+ { { pre-of>> <=> } { def-index>> <=> } } compare-with-spec ;
SYMBOLS: blue red ;
: following-stack-state ( insns -- state )
T{ ##branch } suffix insns>cfg trace-stack-state
- >alist [ first ] sort-with last second ;
+ >alist [ first ] sort-by last second ;
! trace-stack-state
{
"USING: sorting kernel math.order ;
IN: compiler.tests.redefine5
GENERIC: my-generic ( a -- b )
- M: object my-generic [ <=> ] sort ;
+ M: object my-generic sort ;
: my-inline ( a -- b ) my-generic ;"
eval( -- )
] unit-test
GENERIC: my-generic ( a -- b )
! We add the bogus quotation here to hinder inlining
! since otherwise we cannot trigger this bug.
- M: my-mixin my-generic 1 + [ [ <=> ] sort ] drop ;"
+ M: my-mixin my-generic 1 + [ sort ] drop ;"
eval( -- )
] unit-test
GENERIC: my-generic ( a -- b )
! We add the bogus quotation here to hinder inlining
! since otherwise we cannot trigger this bug.
- M: my-mixin my-generic 1 + [ [ <=> ] sort ] drop ;"
+ M: my-mixin my-generic 1 + [ sort ] drop ;"
eval( -- )
] unit-test
USING: compiler.tree.debugger tools.test sorting sequences io math.order ;
IN: compiler.tree.debugger.tests
-[ [ <=> ] sort ] optimized.
+[ [ <=> ] sort-with ] optimized.
[ <reversed> [ print ] each ] optimizer-report.
{ methods-called "==== Non-inlined method calls:" }
{ intrinsics-called "==== Open-coded intrinsic calls:" }
} [
- nl print get keys natural-sort stack.
+ nl print get keys sort stack.
] assoc-each
] with-variables ;
[ [ 1 ] [ 2 ] compose swap [ 1 ] [ 2 ] if + * ]
[ dup slice? [ dup array? [ ] [ ] if ] [ ] if ]
[ dup [ drop f ] [ "A" throw ] if ]
- [ [ <=> ] sort ]
+ [ [ <=> ] sort-with ]
[ [ <=> ] with search ]
} [
[ ] swap [ test-def-use ] curry unit-test
{ { #call #return } } [
[ 1 dup reverse ] build-tree compute-def-use
first out-d>> first actually-used-by
- [ node>> class-of ] map natural-sort
+ [ node>> class-of ] map sort
] unit-test
: word-1 ( a -- b ) dup [ word-1 ] when ; inline recursive
{ { #introduce } } [
[ word-1 ] build-tree analyze-recursive compute-def-use
last in-d>> first actually-defined-by
- [ node>> class-of ] map natural-sort
+ [ node>> class-of ] map sort
] unit-test
{ { #if #return } } [
[ word-1 ] build-tree analyze-recursive compute-def-use
first out-d>> first actually-used-by
- [ node>> class-of ] map natural-sort
+ [ node>> class-of ] map sort
] unit-test
{ V{ t } } [ [ macosx unix? ] final-literals ] unit-test
-{ V{ array } } [ [ [ <=> ] sort [ <=> ] sort ] final-classes ] unit-test
+{ V{ array } } [ [ [ <=> ] sort-with [ <=> ] sort-with ] final-classes ] unit-test
{ V{ float } } [ [ fsqrt ] final-classes ] unit-test
[ [ ] [ ] curry curry dup 2 slot swap 3 slot dup 2 slot swap 3 slot drop ]
[ [ ] [ ] curry curry call ]
[ 1 cons boa over [ "A" throw ] when car>> ]
- [ [ <=> ] sort ]
+ [ [ <=> ] sort-with ]
[ [ <=> ] with search ]
[ cons boa car>> void { } cdecl [ ] alien-callback ]
} [ [ ] swap [ test-unboxing ] curry unit-test ] each
} cond ;
: sort-values! ( obj -- sortedseq )
- >alist [ <==> ] sort ;
+ >alist [ <==> ] sort-with ;
: get-next-code ( code current -- next )
[ reverse bit-array>integer 1 + ] [ length ] bi <bits> >bit-array reverse dup length pick length swap - [ f ] replicate append nip ;
: get-table ( values size -- table )
16 f <array> <enumerated>
[ '[ _ push-at ] 2each ] keep
- seq>> rest-slice [ natural-sort ] map ; inline
+ seq>> rest-slice [ sort ] map ; inline
:: decode-huffman-tables ( bitstream -- tables )
5 bitstream bs:read 257 +
! Copyright (C) 2023 Doug Coleman.
+! Copyright (C) 2023 Giftpflanze.
! See https://factorcode.org/license.txt for BSD license.
USING: cpu.arm.assembler cpu.arm.assembler.opcodes kernel math ;
IN: cpu.arm.assembler.32
! Copyright (C) 2023 Doug Coleman.
+! Copyright (C) 2023 Giftpflanze.
! See https://factorcode.org/license.txt for BSD license.
USING: cpu.arm.assembler cpu.arm.assembler.opcodes kernel math
math.bitwise ;
! Copyright (C) 2020 Doug Coleman.
+! Copyright (C) 2023 Giftpflanze.
! See https://factorcode.org/license.txt for BSD license.
USING: combinators cpu.arm.assembler.opcodes grouping kernel
math math.bitwise math.parser sequences ;
! Copyright (C) 2020 Doug Coleman.
+! Copyright (C) 2023 Giftpflanze.
! See https://factorcode.org/license.txt for BSD license.
USING: accessors assocs classes.error classes.parser effects
effects.parser endian kernel lexer make math math.bitwise
1 1 things boa insert-tuple
1 0 things boa insert-tuple
f f things boa select-tuples
- [ [ one>> ] [ two>> ] bi 2array ] map natural-sort
+ [ [ one>> ] [ two>> ] bi 2array ] map sort
things drop-table
] with-db
] unit-test
[ { "test" "test2" } ] [
select-me new NULL >>data [ "test" >>data ] update-tuples
select-me new [ data>> ] collector [ each-tuple ] dip
- natural-sort
+ sort
] unit-test
[ { "test1" "test2" } ] [
dup data>> "test" = [ "test1" >>data ] [ drop f ] if
] update-tuples
select-me new [ data>> ] collector [ each-tuple ] dip
- natural-sort
+ sort
] unit-test
[ { "test2" } ] [
select-me new [ data>> "test1" = ] reject-tuples
select-me new [ data>> ] collector [ each-tuple ] dip
- natural-sort
+ sort
] unit-test ;
[ test-mapping ] test-sqlite
: write-keywords ( vocab -- )
lookup-vocab
- [ name>> ] [ vocab-words [ name>> ] map ] bi natural-sort [
+ [ name>> ] [ vocab-words [ name>> ] map ] bi sort [
[ vocab-name>syntax-group-name
[ "SynKeywordFactorWord " write write " | " write ] keep
] dip
[ length ] histogram-by
dup keys length [0..b]
[ [ of ] keep over [ 10^ < ] [ nip ] if ] with find nip
- [ '[ length _ = ] filter natural-sort ] keep ! remove natural-sort here
+ [ '[ length _ = ] filter sort ] keep ! remove sort here
[
[ drop "" ] [
10^ <iota> [
CONSTANT: vocab-renames {
{ "math.intervals" { "intervals" "0.99" } }
{ "math.ranges" { "ranges" "0.99" } }
+ { "sorting.slots" { "sorting.specification" "0.99" } }
}
CONSTANT: word-renames {
{ "deep-subseq?" { "deep-subseq-of?" "0.99" } }
{ "overtomorrow" { "overmorrow" "0.99" } }
{ "INITIALIZE:" { "INITIALIZED-SYMBOL:" "0.99" } }
+ { "natural-sort" { "sort" "0.99" } }
+ { "sort-by-with" { "sort-with-spec-by" "0.99" } }
+ { "sort-keys-by" { "sort-keys-with-spec" "0.99" } }
+ { "sort-values-by" { "sort-values-with-spec" "0.99" } }
+ { "compare-slots" { "compare-with-spec" "0.99" } }
+ { "natural-sort!" { "sort!" "0.99" } }
+ { "natural-bubble-sort!" { "bubble-sort!" "0.99" } }
}
: compute-assoc-fixups ( continuation name assoc -- seq )
"a/e/g" make-directory
"a/e/g/e" touch-file
- "**" glob natural-sort
- "**/" glob natural-sort
- "**/*" glob natural-sort
- "**/**" glob natural-sort
- "**/b" glob natural-sort
- "**/e" glob natural-sort
- ! "**//e" glob natural-sort
- ! "**/**/e" glob natural-sort
- "**/e/**" glob natural-sort
- "a/**" glob natural-sort
- "a" glob natural-sort
- "a/b" glob natural-sort
+ "**" glob sort
+ "**/" glob sort
+ "**/*" glob sort
+ "**/**" glob sort
+ "**/b" glob sort
+ "**/e" glob sort
+ ! "**//e" glob sort
+ ! "**/**/e" glob sort
+ "**/e/**" glob sort
+ "a/**" glob sort
+ "a" glob sort
+ "a/b" glob sort
] with-test-directory
] unit-test
dup assert-heap-invariant
data>>
[ [ key>> ] map ] bi@
- [ natural-sort ] bi@ ;
+ [ sort ] bi@ ;
11 [
[ t ] swap [ 2^ delete-test sequence= ] curry unit-test
] "" make ;
M: more-completions article-content
- seq>> [ second >lower ] sort-with keys \ $completions prefix ;
+ seq>> [ second >lower ] sort-by keys \ $completions prefix ;
:: (apropos) ( search completions category -- element )
completions [
] [
first '[ article-words [ _ head? ] any? ] filter
] if
- ] if-empty [ article-name ] sort-with ;
+ ] if-empty [ article-name ] sort-by ;
PRIVATE>
[
"Words" $heading
- natural-sort
+ sort
[ [ class? ] filter describe-classes ]
[
[ [ class? ] [ symbol? ] bi and ] reject
: keyed-vocabs ( str quot -- seq )
[ all-disk-vocabs-recursive ] 2dip '[
[ _ swap @ member? ] filter no-prefixes
- [ name>> ] sort-with
+ [ name>> ] sort-by
] assoc-map ; inline
: tagged ( tag -- assoc )
[ ?toggle-sort-order ] 2bi append
] curry tri@ ;
-: listing-sort-with ( seq quot: ( elt -- key ) -- sortedseq )
- sort-with sort-asc? [ reverse ] unless ; inline
+: listing-sort-by ( seq quot: ( elt -- key ) -- sortedseq )
+ sort-by sort-asc? [ reverse ] unless ; inline
-: sort-with-name ( {file,info} -- sorted )
- [ first ] listing-sort-with ;
+: sort-by-name ( {file,info} -- sorted )
+ [ first ] listing-sort-by ;
-: sort-with-modified ( {file,info} -- sorted )
- [ second modified>> ] listing-sort-with ;
+: sort-by-modified ( {file,info} -- sorted )
+ [ second modified>> ] listing-sort-by ;
: size-without-directories ( info -- size )
dup directory? [ drop -1 ] [ size>> ] if ;
-: sort-with-size ( {file,info} -- sorted )
- [ second size-without-directories ] listing-sort-with ;
+: sort-by-size ( {file,info} -- sorted )
+ [ second size-without-directories ] listing-sort-by ;
: sort-listing ( zipped-files-infos -- sorted )
sort-column {
- { "M" [ sort-with-modified ] }
- { "S" [ sort-with-size ] }
- [ drop sort-with-name ]
+ { "M" [ sort-by-modified ] }
+ { "S" [ sort-by-size ] }
+ [ drop sort-by-name ]
} case ; inline
: zip-files-infos ( files -- zipped )
interval-map check-instance array>> [ third-unsafe ] map ;
: <interval-map> ( specification -- map )
- all-intervals [ first-unsafe second-unsafe ] sort-with
+ all-intervals [ first-unsafe second-unsafe ] sort-by
>intervals ensure-disjoint interval-map boa ;
: <interval-set> ( specification -- map )
{ t } [
[
10 [ "io.paths.test" "gogogo" unique-file ] replicate
- "." [ ] find-files [ absolute-path ] map [ natural-sort ] same?
+ "." [ ] find-files [ absolute-path ] map [ sort ] same?
] with-test-directory
] unit-test
! preserve file traversal order, but sort
! alphabetically for cross-platform testing
- dup length 3 / group natural-sort
- [ natural-sort ] map concat
+ dup length 3 / group sort
+ [ sort ] map concat
] with-variable
+breadth-first+ traversal-method [
! preserve file traversal order, but sort
! alphabetically for cross-platform testing
[ [ length ] bi@ = ] monotonic-split
- [ natural-sort ] map concat
+ [ sort ] map concat
] with-variable
] with-test-directory
] unit-test
] [
group-factors dup empty? [
[ first2 [0..b] [ ^ ] with map ] map
- [ product ] product-map natural-sort
+ [ product ] product-map sort
] unless
] if ;
] [
[ (pollard-rho-brent-factors) ] { } make
] if
- ] if natural-sort ;
+ ] if sort ;
PRIVATE>
: trimmed-mean ( seq p -- x )
- swap natural-sort trim-points <slice> mean ;
+ swap sort trim-points <slice> mean ;
: winsorized-mean ( seq p -- x )
- swap natural-sort trim-points
+ swap sort trim-points
[ <slice> ]
[ nip dupd nth <array> ]
[ [ 1 - ] dip nth <array> ] 3tri
dup dcg [
drop 0.0
] [
- swap natural-sort <reversed> dcg /f
+ swap sort <reversed> dcg /f
] if-zero
] if-empty ;
{ "text" "text2" }
} [
upload3 [ separator3 parse-multipart ] with-string-reader
- keys natural-sort
+ keys sort
] unit-test
SYMBOL: mime-test-server
IN: models.sort
: <sort> ( values sort -- model )
- [ '[ _ call( obj1 obj2 -- <=> ) ] sort ] <smart-arrow> ; inline
+ [ '[ _ call( obj1 obj2 -- <=> ) ] sort-with ] <smart-arrow> ; inline
:: initialize-partitions ( transition-table -- partitions )
! Partition table is sorted-array => ?
- transition-table transitions>> keys natural-sort :> states
+ transition-table transitions>> keys sort :> states
states length 2/ sq <hash-set> :> out
states [| s1 i1 |
states [| s2 |
] each partitions dup cardinality size = not ;
: partition>classes ( partitions -- synonyms ) ! old-state => new-state
- members natural-sort <reversed> [ swap ] H{ } assoc-map-as ;
+ members inv-sort [ swap ] H{ } assoc-map-as ;
: (state-classes) ( transition-table -- partition )
[ initialize-partitions ] keep '[ _ partition-more ] loop ;
dup implementors
[ [ reader? ] [ writer? ] bi or ] reject
[ lookup-method ] with map
- natural-sort ;
+ sort ;
: seeing-methods ( generic -- seq )
- "methods" word-prop values natural-sort ;
+ "methods" word-prop values sort ;
PRIVATE>
: see-all ( seq -- )
- natural-sort [ nl nl ] [ see* ] interleave ;
+ sort [ nl nl ] [ see* ] interleave ;
: methods ( word -- seq )
[
! See https://factorcode.org/license.txt for BSD license.
USING: accessors circular combinators.short-circuit io kernel
math math.order sequences sequences.parser sequences.private
-sorting.functor sorting.slots unicode ;
+sorting unicode ;
IN: sequences.parser
TUPLE: sequence-parser sequence n ;
sequence-parser [ n + ] change-n drop
] if ;
-<< "length" [ length ] define-sorting >>
-
-: sort-tokens ( seq -- seq' )
- { length>=< <=> } sort-by ;
+: sort-tokens ( seq -- seq' ) [ length ] inv-sort-by ;
: take-first-matching ( sequence-parser seq -- seq )
swap
-USING: sorting.human tools.test sorting.slots sorting ;
+USING: sorting.human tools.test sorting ;
{ { "x1y" "x2" "x10y" } }
-[ { "x1y" "x10y" "x2" } { human<=> } sort-by ] unit-test
+[ { "x1y" "x10y" "x2" } [ human<=> ] sort-with ] unit-test
{ { "4dup" "nip" } }
-[ { "4dup" "nip" } [ human<=> ] sort ] unit-test
+[ { "4dup" "nip" } [ human<=> ] sort-with ] unit-test
{ { "4dup" "nip" } }
-[ { "nip" "4dup" } [ human<=> ] sort ] unit-test
+[ { "nip" "4dup" } [ human<=> ] sort-with ] unit-test
{ { "4dup" "4nip" "5drop" "nip" "nip2" "nipd" } }
-[ { "nip" "4dup" "4nip" "5drop" "nip2" "nipd" } [ human<=> ] sort ] unit-test
+[ { "nip" "4dup" "4nip" "5drop" "nip2" "nipd" } [ human<=> ] sort-with ] unit-test
{ { "Abc" "abc" "def" "gh" } }
-[ { "abc" "Abc" "def" "gh" } [ human<=> ] sort ] unit-test
+[ { "abc" "Abc" "def" "gh" } [ human<=> ] sort-with ] unit-test
{ { "abc" "Abc" "def" "gh" } }
-[ { "abc" "Abc" "def" "gh" } [ humani<=> ] sort ] unit-test
+[ { "abc" "Abc" "def" "gh" } [ humani<=> ] sort-with ] unit-test
<< "human" [ find-numbers [ <alphanum> ] map ] define-sorting >>
<< "humani" [ find-numbers [ <alphanum-insensitive> ] map ] define-sorting >>
-: human-sort ( seq -- seq' ) [ human<=> ] sort ;
-: humani-sort ( seq -- seq' ) [ humani<=> ] sort ;
+: human-sort ( seq -- seq' ) [ human<=> ] sort-with ;
+: humani-sort ( seq -- seq' ) [ humani<=> ] sort-with ;
+++ /dev/null
-Doug Coleman
-Slava Pestov
+++ /dev/null
-! Copyright (C) 2009 Doug Coleman.
-! See https://factorcode.org/license.txt for BSD license.
-USING: help.markup help.syntax kernel quotations math.order
-sequences ;
-IN: sorting.slots
-
-HELP: compare-slots
-{ $values
- { "obj1" object }
- { "obj2" object }
- { "sort-specs" "a sequence of accessors ending with a comparator" }
- { "<=>" { $link +lt+ } " " { $link +eq+ } " or " { $link +gt+ } }
-}
-{ $description "Compares two objects using a chain of intrinsic linear orders such that if two objects are " { $link +eq+ } ", then the next comparator is tried. The comparators are slot-name/comparator pairs." } ;
-
-HELP: sort-by
-{ $values
- { "seq" sequence } { "sort-specs" "a sequence of accessors ending with a comparator" }
- { "seq'" sequence }
-}
-{ $description "Sorts a sequence of tuples by the sort-specs in " { $snippet "sort-spec" } ". A sort-spec is a sequence of slot accessors ending in a comparator." }
-{ $examples
- "Sort by slot a, then b descending:"
- { $example
- "USING: accessors math.order prettyprint sorting.slots ;"
- "IN: scratchpad"
- "TUPLE: sort-me a b ;"
- "{"
- " T{ sort-me f 2 3 } T{ sort-me f 3 2 }"
- " T{ sort-me f 4 3 } T{ sort-me f 2 1 }"
- "}"
- "{ { a>> <=> } { b>> >=< } } sort-by ."
- "{\n T{ sort-me { a 2 } { b 3 } }\n T{ sort-me { a 2 } { b 1 } }\n T{ sort-me { a 3 } { b 2 } }\n T{ sort-me { a 4 } { b 3 } }\n}"
- }
-} ;
-
-ARTICLE: "sorting.slots" "Sorting by slots"
-"The " { $vocab-link "sorting.slots" } " vocabulary can sort tuples by slot in ascending or descending order, using subsequent slots as tie-breakers." $nl
-"Comparing two objects by a sequence of slots:"
-{ $subsections compare-slots }
-"Sorting a sequence of tuples by a slot/comparator pairs:"
-{ $subsections
- sort-by
- sort-keys-by
- sort-values-by
-} ;
-
-ABOUT: "sorting.slots"
+++ /dev/null
-! Copyright (C) 2009 Doug Coleman.
-! See https://factorcode.org/license.txt for BSD license.
-USING: accessors math.order sorting.slots tools.test
-arrays sequences kernel assocs multiline sorting.functor ;
-IN: sorting.literals.tests
-
-TUPLE: sort-test a b c tuple2 ;
-
-TUPLE: tuple2 d ;
-
-{
- {
- T{ sort-test { a 1 } { b 3 } { c 9 } }
- T{ sort-test { a 1 } { b 1 } { c 10 } }
- T{ sort-test { a 1 } { b 1 } { c 11 } }
- T{ sort-test { a 2 } { b 5 } { c 2 } }
- T{ sort-test { a 2 } { b 5 } { c 3 } }
- }
-} [
- {
- T{ sort-test f 1 3 9 }
- T{ sort-test f 1 1 10 }
- T{ sort-test f 1 1 11 }
- T{ sort-test f 2 5 3 }
- T{ sort-test f 2 5 2 }
- } { { a>> <=> } { b>> >=< } { c>> <=> } } sort-by
-] unit-test
-
-{
- {
- T{ sort-test { a 1 } { b 3 } { c 9 } }
- T{ sort-test { a 1 } { b 1 } { c 10 } }
- T{ sort-test { a 1 } { b 1 } { c 11 } }
- T{ sort-test { a 2 } { b 5 } { c 2 } }
- T{ sort-test { a 2 } { b 5 } { c 3 } }
- }
-} [
- {
- T{ sort-test f 1 3 9 }
- T{ sort-test f 1 1 10 }
- T{ sort-test f 1 1 11 }
- T{ sort-test f 2 5 3 }
- T{ sort-test f 2 5 2 }
- } { { a>> <=> } { b>> >=< } { c>> <=> } } sort-by
-] unit-test
-
-{ { } }
-[ { } { { a>> <=> } { b>> >=< } { c>> <=> } } sort-by ] unit-test
-
-{ { } }
-[ { } { } sort-by ] unit-test
-
-{
- {
- T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 1 } } } }
- T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 2 } } } }
- T{ sort-test { a 5 } { tuple2 T{ tuple2 { d 3 } } } }
- T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 3 } } } }
- T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 3 } } } }
- T{ sort-test { a 5 } { tuple2 T{ tuple2 { d 4 } } } }
- }
-} [
- {
- T{ sort-test f 6 f f T{ tuple2 f 1 } }
- T{ sort-test f 5 f f T{ tuple2 f 4 } }
- T{ sort-test f 6 f f T{ tuple2 f 3 } }
- T{ sort-test f 6 f f T{ tuple2 f 3 } }
- T{ sort-test f 5 f f T{ tuple2 f 3 } }
- T{ sort-test f 6 f f T{ tuple2 f 2 } }
- } { { tuple2>> d>> <=> } { a>> <=> } } sort-by
-] unit-test
-
-
-{ { "a" "b" "c" } } [ { "b" "c" "a" } { <=> <=> } sort-by ] unit-test
-{ { "b" "c" "a" } } [ { "b" "c" "a" } { } sort-by ] unit-test
-
-<< "length-test" [ length ] define-sorting >>
-
-{ { { 1 } { 1 2 3 } { 1 3 2 } { 3 2 1 } } }
-[
- { { 3 2 1 } { 1 2 3 } { 1 3 2 } { 1 } }
- { length-test<=> <=> } sort-by
-] unit-test
-
-{ { { { 0 } 1 } { { 1 } 2 } { { 1 } 1 } { { 3 1 } 2 } } }
-[
- { { { 3 1 } 2 } { { 1 } 2 } { { 0 } 1 } { { 1 } 1 } }
- { length-test<=> <=> } sort-keys-by
-] unit-test
-
-{ { { 0 { 1 } } { 1 { 1 } } { 3 { 2 4 } } { 1 { 2 0 0 0 } } } }
-[
- { { 3 { 2 4 } } { 1 { 2 0 0 0 } } { 0 { 1 } } { 1 { 1 } } }
- { length-test<=> <=> } sort-values-by
-] unit-test
-
-{ { { "apples" 1 } { "bananas" 2 } { "cherries" 3 } } } [
- H{ { "apples" 1 } { "bananas" 2 } { "cherries" 3 } }
- { { sequences:length <=> } } sort-keys-by
-] unit-test
+++ /dev/null
-! Copyright (C) 2009 Slava Pestov, Doug Coleman.
-! See https://factorcode.org/license.txt for BSD license.
-USING: arrays assocs fry kernel math.order sequences sorting ;
-IN: sorting.slots
-
-: execute-comparator ( obj1 obj2 word -- <=>/f )
- execute( obj1 obj2 -- <=> ) dup +eq+ eq? [ drop f ] when ;
-
-: execute-accessor ( obj1 obj2 word -- obj1' obj2' )
- '[ _ execute( tuple -- value ) ] bi@ ;
-
-: compare-slots ( obj1 obj2 sort-specs -- <=> )
- ! sort-spec: { accessors comparator }
- [
- dup array? [
- unclip-last-slice
- [ [ execute-accessor ] each ] dip
- ] when execute-comparator
- ] 2with map-find drop +eq+ or ;
-
-: sort-by-with ( seq sort-specs quot: ( obj -- key ) -- seq' )
- swap '[ _ bi@ _ compare-slots ] sort ; inline
-
-: sort-by ( seq sort-specs -- seq' ) [ ] sort-by-with ;
-
-: sort-keys-by ( alist sort-seq -- seq' )
- [ >alist ] dip [ first ] sort-by-with ;
-
-: sort-values-by ( seq sort-seq -- seq' )
- [ >alist ] dip [ second ] sort-by-with ;
+++ /dev/null
-Sorting by tuple slots
--- /dev/null
+Doug Coleman
+Slava Pestov
--- /dev/null
+! Copyright (C) 2009 Doug Coleman.
+! See https://factorcode.org/license.txt for BSD license.
+USING: help.markup help.syntax kernel quotations math.order
+sequences ;
+IN: sorting.specification
+
+HELP: compare-with-spec
+{ $values
+ { "obj1" object }
+ { "obj2" object }
+ { "sort-spec" "a sequence of sequences of accessors and a comparator" }
+ { "<=>" { $link +lt+ } ", " { $link +eq+ } " or " { $link +gt+ } }
+}
+{ $description "Compares two objects using a chain of intrinsic linear orders such that if two objects are " { $link +eq+ } ", then the next ordering is tried." } ;
+
+HELP: sort-with-spec
+{ $values
+ { "seq" sequence } { "sort-spec" "a sequence of sequences of accessors and a comparator" }
+ { "seq'" sequence }
+}
+{ $description "Sorts a sequence of objects by the sorting specification in " { $snippet "sort-spec" } ". A sorting specification is a sequence of sequences, each consisting of accessors and a comparator." }
+{ $examples
+ "Sort by slot a, then b descending:"
+ { $example
+ "USING: accessors math.order prettyprint sorting.specification ;"
+ "IN: scratchpad"
+ "TUPLE: sort-me a b ;"
+ "{"
+ " T{ sort-me f 2 3 } T{ sort-me f 3 2 }"
+ " T{ sort-me f 4 3 } T{ sort-me f 2 1 }"
+ "}"
+ "{ { a>> <=> } { b>> >=< } } sort-with-spec ."
+ "{\n T{ sort-me { a 2 } { b 3 } }\n T{ sort-me { a 2 } { b 1 } }\n T{ sort-me { a 3 } { b 2 } }\n T{ sort-me { a 4 } { b 3 } }\n}"
+ }
+} ;
+
+ARTICLE: "sorting.specification" "Sorting by multiple keys"
+"The " { $vocab-link "sorting.specification" } " vocabulary can sort objects by multiple keys in ascending or descending order, using subsequent keys as tie-breakers." $nl
+"Comparing two objects with a sorting specification:"
+{ $subsections compare-with-spec }
+"Sorting a sequence of objects with a sorting specification:"
+{ $subsections
+ sort-with-spec
+ sort-keys-with-spec
+ sort-values-with-spec
+} ;
+
+ABOUT: "sorting.specification"
--- /dev/null
+! Copyright (C) 2009 Doug Coleman.
+! See https://factorcode.org/license.txt for BSD license.
+USING: accessors math.order sorting.specification tools.test
+arrays sequences kernel assocs multiline sorting.functor ;
+IN: sorting.specification.tests
+
+TUPLE: sort-test a b c tuple2 ;
+
+TUPLE: tuple2 d ;
+
+{
+ {
+ T{ sort-test { a 1 } { b 3 } { c 9 } }
+ T{ sort-test { a 1 } { b 1 } { c 10 } }
+ T{ sort-test { a 1 } { b 1 } { c 11 } }
+ T{ sort-test { a 2 } { b 5 } { c 2 } }
+ T{ sort-test { a 2 } { b 5 } { c 3 } }
+ }
+} [
+ {
+ T{ sort-test f 1 3 9 }
+ T{ sort-test f 1 1 10 }
+ T{ sort-test f 1 1 11 }
+ T{ sort-test f 2 5 3 }
+ T{ sort-test f 2 5 2 }
+ } { { a>> <=> } { b>> >=< } { c>> <=> } } sort-with-spec
+] unit-test
+
+{
+ {
+ T{ sort-test { a 1 } { b 3 } { c 9 } }
+ T{ sort-test { a 1 } { b 1 } { c 10 } }
+ T{ sort-test { a 1 } { b 1 } { c 11 } }
+ T{ sort-test { a 2 } { b 5 } { c 2 } }
+ T{ sort-test { a 2 } { b 5 } { c 3 } }
+ }
+} [
+ {
+ T{ sort-test f 1 3 9 }
+ T{ sort-test f 1 1 10 }
+ T{ sort-test f 1 1 11 }
+ T{ sort-test f 2 5 3 }
+ T{ sort-test f 2 5 2 }
+ } { { a>> <=> } { b>> >=< } { c>> <=> } } sort-with-spec
+] unit-test
+
+{ { } } [
+ { } { { a>> <=> } { b>> >=< } { c>> <=> } } sort-with-spec
+] unit-test
+
+{ { } } [ { } { } sort-with-spec ] unit-test
+
+{
+ {
+ T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 1 } } } }
+ T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 2 } } } }
+ T{ sort-test { a 5 } { tuple2 T{ tuple2 { d 3 } } } }
+ T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 3 } } } }
+ T{ sort-test { a 6 } { tuple2 T{ tuple2 { d 3 } } } }
+ T{ sort-test { a 5 } { tuple2 T{ tuple2 { d 4 } } } }
+ }
+} [
+ {
+ T{ sort-test f 6 f f T{ tuple2 f 1 } }
+ T{ sort-test f 5 f f T{ tuple2 f 4 } }
+ T{ sort-test f 6 f f T{ tuple2 f 3 } }
+ T{ sort-test f 6 f f T{ tuple2 f 3 } }
+ T{ sort-test f 5 f f T{ tuple2 f 3 } }
+ T{ sort-test f 6 f f T{ tuple2 f 2 } }
+ } { { tuple2>> d>> <=> } { a>> <=> } } sort-with-spec
+] unit-test
+
+
+{ { "a" "b" "c" } } [ { "b" "c" "a" } { <=> <=> } sort-with-spec ] unit-test
+{ { "b" "c" "a" } } [ { "b" "c" "a" } { } sort-with-spec ] unit-test
+
+<< "length-test" [ length ] define-sorting >>
+
+{ { { 1 } { 1 2 3 } { 1 3 2 } { 3 2 1 } } }
+[
+ { { 3 2 1 } { 1 2 3 } { 1 3 2 } { 1 } }
+ { length-test<=> <=> } sort-with-spec
+] unit-test
+
+{ { { { 0 } 1 } { { 1 } 2 } { { 1 } 1 } { { 3 1 } 2 } } }
+[
+ { { { 3 1 } 2 } { { 1 } 2 } { { 0 } 1 } { { 1 } 1 } }
+ { length-test<=> <=> } sort-keys-with-spec
+] unit-test
+
+{ { { 0 { 1 } } { 1 { 1 } } { 3 { 2 4 } } { 1 { 2 0 0 0 } } } }
+[
+ { { 3 { 2 4 } } { 1 { 2 0 0 0 } } { 0 { 1 } } { 1 { 1 } } }
+ { length-test<=> <=> } sort-values-with-spec
+] unit-test
+
+{ { { "apples" 1 } { "bananas" 2 } { "cherries" 3 } } } [
+ H{ { "apples" 1 } { "bananas" 2 } { "cherries" 3 } }
+ { { sequences:length <=> } } sort-keys-with-spec
+] unit-test
--- /dev/null
+! Copyright (C) 2009 Slava Pestov, Doug Coleman.
+! See https://factorcode.org/license.txt for BSD license.
+USING: arrays assocs kernel math.order sequences sorting ;
+IN: sorting.specification
+
+: execute-comparator ( obj1 obj2 word -- <=>/f )
+ execute( obj1 obj2 -- <=> ) dup +eq+ eq? [ drop f ] when ;
+
+: execute-accessor ( obj1 obj2 word -- obj1' obj2' )
+ '[ _ execute( tuple -- value ) ] bi@ ;
+
+: compare-with-spec ( obj1 obj2 sort-spec -- <=> )
+ ! sort-spec: { { accessor ... comparator } ... }
+ [
+ dup array? [
+ unclip-last-slice
+ [ [ execute-accessor ] each ] dip
+ ] when execute-comparator
+ ] 2with map-find drop +eq+ or ;
+
+: sort-with-spec-by ( seq sort-spec quot: ( obj -- key ) -- sortedseq )
+ swap '[ _ bi@ _ compare-with-spec ] sort-with ; inline
+
+: sort-with-spec ( seq sort-spec -- seq' ) [ ] sort-with-spec-by ;
+
+: sort-keys-with-spec ( assoc sort-spec -- alist )
+ [ >alist ] dip [ first ] sort-with-spec-by ;
+
+: sort-values-with-spec ( assoc sort-spec -- alist )
+ [ >alist ] dip [ second ] sort-with-spec-by ;
--- /dev/null
+Sorting by multiple keys
! Copyright (C) 2009 Doug Coleman.
! See https://factorcode.org/license.txt for BSD license.
-USING: tools.test sorting.title sorting.slots ;
+USING: tools.test sorting sorting.title ;
IN: sorting.title.tests
: sort-me ( -- seq )
"la vida loca"
}
} [
- sort-me { title<=> } sort-by
+ sort-me [ title<=> ] sort-with
] unit-test
drop
[ downward-slices ]
[ stable-slices ]
- [ upward-slices ] tri 3append [ from>> ] sort-with
+ [ upward-slices ] tri 3append [ from>> ] sort-by
] [
zero? [ drop { } ] [ [ 0 1 ] dip stable-slice boa ] if
] if ;
PRIVATE>
: >suffix-array ( seq -- suffix-array )
- members [ suffixes ] map concat natural-sort ;
+ members [ suffixes ] map concat sort ;
SYNTAX: SA{ \ } [ >suffix-array ] parse-literal ;
: word-timing. ( -- )
word-timing get >alist
- [ second first ] sort-with
+ [ second first ] sort-by
[ first2 first2 [ 1,000,000,000 /f ] dip 3array ] map
simple-table. ;
{
{ halftested mconcat testcond testfry testif testifprivate testmacro untested
}
-} [ "tools.coverage.testvocab" [ ] map-words natural-sort ] unit-test
+} [ "tools.coverage.testvocab" [ ] map-words sort ] unit-test
{ t } [
"tools.coverage.testvocab"
{
{ testifprivate }
-} [ "tools.coverage.testvocab.private" [ ] map-words natural-sort ] unit-test
+} [ "tools.coverage.testvocab.private" [ ] map-words sort ] unit-test
{ t } [
"tools.coverage.testvocab.private"
{ testmacro { } }
{ untested { [ ] } }
}
-} [ "tools.coverage.testvocab" [ reload ] [ test-coverage natural-sort ] bi ] unit-test
+} [ "tools.coverage.testvocab" [ reload ] [ test-coverage sort ] bi ] unit-test
{ 0.75 } [ "tools.coverage.testvocab.child" [ reload ] [ %coverage ] bi ] unit-test
}
} [
"tools.coverage.testvocab.child" reload
- "tools.coverage.testvocab" [ reload ] [ test-coverage-recursively ] bi natural-sort
- [ first2 natural-sort 2array ] map
+ "tools.coverage.testvocab" [ reload ] [ test-coverage-recursively ] bi sort
+ [ first2 sort 2array ] map
] unit-test
[ "method-generic" word-prop ] when
vocabulary>>
] map
- ] gather natural-sort remove sift ; inline
+ ] gather sort remove sift ; inline
: vocabs. ( seq -- )
[ dup >vocab-link write-object nl ] each ;
members [ class-of ] collect-by ;
: (disposables.) ( set -- )
- class-tally >alist [ first2 [ length ] keep 3array ] map [ second ] sort-with
+ class-tally >alist [ first2 [ length ] keep 3array ] map [ second ] sort-by
standard-table-style [
[
[ "Disposable class" write ] with-cell
] tabular-output nl ;
: sort-disposables ( seq -- seq' )
- [ disposable? ] partition [ [ id>> ] sort-with ] dip append ;
+ [ disposable? ] partition [ [ id>> ] sort-by ] dip append ;
PRIVATE>
! See https://factorcode.org/license.txt for BSD license.
USING: accessors arrays calendar calendar.english
calendar.format combinators io.directories io.files.info kernel
-math math.parser prettyprint sequences sorting.slots splitting
-system vocabs ;
+math math.parser prettyprint sequences sorting.specification
+splitting system vocabs ;
IN: tools.files
<PRIVATE
: list-files-slow ( listing-tool -- array )
[ path>> ] [ sort>> ] [ specs>> ] tri '[
[ dup name>> link-info file-listing boa ] map
- _ [ sort-by ] when*
+ _ [ sort-with-spec ] when*
[ _ [ file-spec>string ] with map ] map
] with-directory-entries ; inline
[ '[ _ _ heap-stat-step ] each ] 2keep ;
: heap-stats. ( -- )
- heap-stats dup keys natural-sort standard-table-style [
+ heap-stats dup keys sort standard-table-style [
[ { "Class" "Bytes" "Instances" } [ write-cell ] each ] with-row
[
[
H{ } [ " " <repetition> concat ] cache write ;
: by-total-time ( nodes -- nodes' )
- >alist [ second total-time>> ] inv-sort-with ;
+ >alist [ second total-time>> ] inv-sort-by ;
: duration. ( duration -- )
1000 * "%9.1f" printf ;
: interesting-words ( vocab -- array )
vocab-words
[ { [ "help" word-prop ] [ predicate? ] } 1|| ] reject
- natural-sort ;
+ sort ;
: interesting-words. ( vocab -- )
interesting-words [ (help.) nl ] each ;
: write-using ( vocab -- )
"USING:" write
using get members
- { "help.markup" "help.syntax" } append natural-sort remove
+ { "help.markup" "help.syntax" } append sort remove
[ bl write ] each
" ;" print ;
1array
<grid>
{ 100 100 } >>dim
- compute-grid-lines natural-sort
+ compute-grid-lines sort
] unit-test
{
<grid>
{ 10 10 } >>gap
dup prefer
- compute-grid-lines natural-sort
+ compute-grid-lines sort
] unit-test
{
2array
<grid>
{ 200.0 200 } >>dim
- compute-grid-lines natural-sort
+ compute-grid-lines sort
] unit-test
{
: <operations-menu> ( target hook -- menu )
over object-operations
[ primary-operation? ] partition
- [ reverse ] [ [ command-name ] sort-with ] bi*
+ [ reverse ] [ [ command-name ] sort-by ] bi*
{ ---- } glue <commands-menu> ;
: show-operations-menu ( gadget target hook -- )
] { } map-index-as ;
M: hashtable make-slot-descriptions
- call-next-method [ key-string>> ] sort-with ;
+ call-next-method [ key-string>> ] sort-by ;
TUPLE: inspector-table < table ;
0 insensitive= ;
: sort-strings ( strings -- sorted )
- [ collation-key/nfd 2array ] map natural-sort values ;
+ [ collation-key/nfd 2array ] map sort values ;
: string<=> ( str1 str2 -- <=> )
[ collation-key/nfd 2array ] compare ;
! See https://factorcode.org/license.txt for BSD license.
USING: accessors arrays combinators combinators.smart
io.encodings.utf8 io.files kernel math math.order math.parser
-memoize sequences sorting.slots splitting splitting.monotonic
-strings io.pathnames calendar words ;
+memoize sequences sorting.specification splitting
+splitting.monotonic strings io.pathnames calendar words ;
IN: unix.linux.proc
! /proc/*
{ "" } split harvest [ lines>processor-info ] map ;
: sort-cpus ( seq -- seq )
- { { physical-id>> <=> } { core-id>> <=> } } sort-by
+ { { physical-id>> <=> } { core-id>> <=> } } sort-with-spec
[ [ physical-id>> ] bi@ = ] monotonic-split
[ [ [ core-id>> ] bi@ = ] monotonic-split ] map ;
{ [ directory? ] [ name>> "." head? not ] } 1&& ;
: visible-dirs ( seq -- seq' )
- [ visible-dir? ] filter [ name>> ] sort-with ;
+ [ visible-dir? ] filter [ name>> ] sort-by ;
ERROR: vocab-root-required root ;
: collect-vocabs ( quot -- seq )
[ all-disk-vocabs-recursive filter-vocabs ] dip
- gather natural-sort ; inline
+ gather sort ; inline
: maybe-include-root/prefix ( root prefix -- vocab-link/f )
over [
! vocab-resource-files
{ { "bar" "bas" "foo" } }
-[ "vocabs.metadata.resources.test.1" vocab-resource-files natural-sort ] unit-test
+[ "vocabs.metadata.resources.test.1" vocab-resource-files sort ] unit-test
{ { "bar.wtf" "foo.wtf" } }
-[ "vocabs.metadata.resources.test.2" vocab-resource-files natural-sort ] unit-test
+[ "vocabs.metadata.resources.test.2" vocab-resource-files sort ] unit-test
{
{
"resource-dir/foo"
}
} [
- "vocabs.metadata.resources.test.3" vocab-resource-files natural-sort
+ "vocabs.metadata.resources.test.3" vocab-resource-files sort
] unit-test
<PRIVATE
-: sort-vocabs ( seq -- seq' )
- [ vocab-name ] sort-with ;
+: sort-vocabs ( seq -- seq' ) [ vocab-name ] sort-by ;
: pprint-using ( seq -- )
"syntax" lookup-vocab '[ _ = ] reject
file>xml parse-modes-tag ;
MEMO: mode-names ( -- modes )
- modes keys natural-sort ;
+ modes keys sort ;
: reset-catalog ( -- )
\ modes reset-memoized ;
assoc>> >alist ;
: (keyword-map-no-word-sep) ( assoc -- str )
- keys union-all [ alpha? ] reject natural-sort ;
+ keys union-all [ alpha? ] reject sort ;
: keyword-map-no-word-sep* ( keyword-map -- str )
dup no-word-sep>> [ ] [
[ topological-sort-failed ] unless* ;
: sort-classes ( seq -- newseq )
- [ class-name ] sort-with >vector
+ [ class-name ] sort-by >vector
[ dup empty? not ]
[ dup largest-class [ swap remove-nth! ] dip ]
produce nip ;
: smallest-class ( classes -- class/f )
[ f ] [
- natural-sort <reversed>
- [ ] [ [ class<= ] most ] map-reduce
+ inv-sort [ ] [ [ class<= ] most ] map-reduce
] if-empty ;
: flatten-class ( class -- seq )
{ { } { } } [
all-words [ class? ] filter
implementors-map get keys
- [ natural-sort ] bi@
+ [ sort ] bi@
[ diff ] [ swap diff ] 2bi
] unit-test
} "g" set
{ { 2 3 4 5 } } [
- 2 [ "g" get at sets:members ] closure sets:members natural-sort
+ 2 [ "g" get at sets:members ] closure sets:members sort
] unit-test
{ t } [ 2 [ "g" get at sets:members ] HS{ } closure-as hash-set? ] unit-test
USING: accessors hash-sets kernel math prettyprint sequences
sets sorting tools.test ;
-{ { 1 2 3 } } [ HS{ 1 2 3 } members natural-sort ] unit-test
+{ { 1 2 3 } } [ HS{ 1 2 3 } members sort ] unit-test
{ "HS{ 1 2 3 4 }" } [ HS{ 1 2 3 4 } unparse ] unit-test
{ t } [ 1 HS{ 1 } ?delete ] unit-test
{ f } [ 1 HS{ } ?delete ] unit-test
{ HS{ 1 2 } } [ HS{ 1 2 } fast-set ] unit-test
-{ { 1 2 } } [ HS{ 1 2 } members natural-sort ] unit-test
+{ { 1 2 } } [ HS{ 1 2 } members sort ] unit-test
{ HS{ 1 2 3 4 } } [ HS{ 1 2 3 } HS{ 2 3 4 } union ] unit-test
{ HS{ 2 3 } } [ HS{ 1 2 3 } HS{ 2 3 4 } intersect ] unit-test
{ 0 } [ 5 <bit-set> 10 over delete cardinality ] unit-test
{ HS{ 1 } } [ HS{ 1 2 } 2 over delete ] unit-test
-{ { 1 2 3 } } [ { 1 1 1 2 2 3 3 3 3 3 } dup set-like natural-sort ] unit-test
-{ { 1 2 3 } } [ HS{ 1 2 3 } { } set-like natural-sort ] unit-test
+{ { 1 2 3 } } [ { 1 1 1 2 2 3 3 3 3 3 } dup set-like sort ] unit-test
+{ { 1 2 3 } } [ HS{ 1 2 3 } { } set-like sort ] unit-test
{ { 1 2 3 } } [ { 1 2 2 3 3 } { } set-like ] unit-test
{ { 3 2 1 } } [ { 3 3 2 2 1 } { } set-like ] unit-test
{ t } [ 4 <bit-set> 1 <bit-set> set-like 4 <bit-set> = ] unit-test
$nl
"The algorithm only allocates two additional arrays, both the size of the input sequence, and uses iteration rather than recursion, and thus is suitable for sorting large sequences."
$nl
-"Sorting combinators all take comparator quotations with stack effect " { $snippet "( elt1 elt2 -- <=> )" } ", where the output value is one of the three " { $link "order-specifiers" } "."
+"Sorting combinators take comparator quotations with stack effect " { $snippet "( elt1 elt2 -- <=> )" } ", where the output value is one of the three " { $link "order-specifiers" } "."
$nl
"Sorting a sequence with a custom comparator:"
-{ $subsections sort }
+{ $subsections sort-with }
"Sorting a sequence with common comparators:"
{ $subsections
- sort-with
- inv-sort-with
- natural-sort
+ sort
+ inv-sort
+ sort-by
+ inv-sort-by
sort-keys
sort-values
} ;
ABOUT: "sequences-sorting"
-HELP: sort
+HELP: sort-with
{ $values { "seq" sequence } { "quot" { $quotation ( obj1 obj2 -- <=> ) } } { "sortedseq" "a new sorted sequence" } }
{ $description "Sorts the elements of " { $snippet "seq" } " into a new array using a stable sort." }
{ $notes "The algorithm used is the merge sort." } ;
-HELP: sort-with
+HELP: sort-by
{ $values { "seq" sequence } { "quot" { $quotation ( elt -- key ) } } { "sortedseq" "a new sorted sequence" } }
{ $description "Sorts the elements of " { $snippet "seq" } " by applying " { $link compare } " with " { $snippet "quot" } " to each pair of elements in the sequence." } ;
-HELP: inv-sort-with
+HELP: inv-sort-by
{ $values { "seq" sequence } { "quot" { $quotation ( elt -- key ) } } { "sortedseq" "a new sorted sequence" } }
{ $description "Sorts the elements of " { $snippet "seq" } " by applying " { $link compare } " with " { $snippet "quot" } " to each pair of elements in the sequence and inverting the results." } ;
{ $values { "obj" object } { "sortedseq" "a new sorted sequence" } }
{ $description "Sorts the elements of " { $snippet "obj" } " (converting to an alist first if not a sequence), comparing second elements of pairs using the " { $link <=> } " word." } ;
-HELP: natural-sort
+HELP: sort
{ $values { "seq" sequence } { "sortedseq" "a new sorted sequence" } }
{ $description "Sorts a sequence of objects in natural order using the " { $link <=> } " word." } ;
{ $values { "a" object } { "b" object } { "c" object } { "d" object } }
{ $description "If " { $snippet "a" } " is greater than " { $snippet "b" } ", exchanges " { $snippet "a" } " with " { $snippet "b" } "." } ;
-HELP: midpoint@
-{ $values { "seq" sequence } { "n" integer } }
-{ $description "Outputs the index of the midpoint of " { $snippet "seq" } "." } ;
-
-{ <=> compare natural-sort sort-with inv-sort-with sort-keys sort-values } related-words
+{ <=> compare sort sort-by inv-sort-by sort-keys sort-values } related-words
USING: grouping kernel math math.order random sequences sets
sorting tools.test vocabs ;
-{ { } } [ { } natural-sort ] unit-test
+{ { } } [ { } sort ] unit-test
{ { 270000000 270000001 } }
-[ T{ slice f 270000000 270000002 T{ iota f 270000002 } } natural-sort ]
+[ T{ slice f 270000000 270000002 T{ iota f 270000002 } } sort ]
unit-test
{ t } [
100 [
drop
100 [ 20 random [ 1000 random ] replicate ] replicate
- dup natural-sort
+ dup sort
[ set= ] [ nip [ before=? ] monotonic? ] 2bi and
] all-integers?
] unit-test
-[ { 1 2 } [ 2drop 1 ] sort ] must-not-fail
+[ { 1 2 } [ 2drop 1 ] sort-with ] must-not-fail
! Is it a stable sort?
{ t } [ { { 1 "a" } { 1 "b" } { 1 "c" } } dup sort-keys = ] unit-test
{ { { 1 "a" } { 1 "b" } { 1 "c" } { 1 "e" } { 2 "d" } } }
[ { { 1 "a" } { 1 "b" } { 1 "c" } { 2 "d" } { 1 "e" } } sort-keys ] unit-test
-[ all-words natural-sort ] must-not-fail
+[ all-words sort ] must-not-fail
PRIVATE>
-: sort ( seq quot: ( obj1 obj2 -- <=> ) -- sortedseq )
+: sort-with ( seq quot: ( obj1 obj2 -- <=> ) -- sortedseq )
[ <merge> ] dip
[ sort-pairs ] [ sort-loop ] [ drop accum>> underlying>> ] 2tri ; inline
-: natural-sort ( seq -- sortedseq ) [ <=> ] sort ;
+: inv-sort-with ( seq quot: ( obj1 obj2 -- <=> ) -- sortedseq )
+ '[ @ invert-comparison ] sort-with ; inline
-: sort-with ( seq quot: ( elt -- key ) -- sortedseq )
- [ compare ] curry sort ; inline
+: sort ( seq -- sortedseq ) [ <=> ] sort-with ;
-: inv-sort-with ( seq quot: ( elt -- key ) -- sortedseq )
- [ compare invert-comparison ] curry sort ; inline
+: inv-sort ( seq -- sortedseq ) [ >=< ] sort-with ;
+
+: sort-by ( seq quot: ( elt -- key ) -- sortedseq )
+ [ compare ] curry sort-with ; inline
+
+: inv-sort-by ( seq quot: ( elt -- key ) -- sortedseq )
+ [ compare invert-comparison ] curry sort-with ; inline
<PRIVATE
PRIVATE>
-GENERIC: sort-keys ( obj -- sortedseq )
+GENERIC: sort-keys ( assoc -- sorted-keys )
M: object sort-keys >alist sort-keys ;
M: sequence sort-keys
- 0 check-bounds [ first-unsafe ] sort-with ;
+ 0 check-bounds [ first-unsafe ] sort-by ;
M: hashtable sort-keys
- >alist [ { array } declare first-unsafe ] sort-with ;
+ >alist [ { array } declare first-unsafe ] sort-by ;
+
+GENERIC: inv-sort-keys ( assoc -- sorted-keys )
+
+M: object inv-sort-keys >alist inv-sort-keys ;
+
+M: sequence inv-sort-keys
+ 0 check-bounds [ first-unsafe ] inv-sort-by ;
-GENERIC: sort-values ( obj -- sortedseq )
+M: hashtable inv-sort-keys
+ >alist [ { array } declare first-unsafe ] inv-sort-by ;
+
+GENERIC: sort-values ( assoc -- sorted-values )
M: object sort-values >alist sort-values ;
M: sequence sort-values
- 1 check-bounds [ second-unsafe ] sort-with ;
+ 1 check-bounds [ second-unsafe ] sort-by ;
M: hashtable sort-values
- >alist [ { array } declare second-unsafe ] sort-with ;
+ >alist [ { array } declare second-unsafe ] sort-by ;
: sort-pair ( a b -- c d ) 2dup after? [ swap ] when ;
+
+GENERIC: inv-sort-values ( assoc -- sorted-values )
+
+M: object inv-sort-values >alist inv-sort-values ;
+
+M: sequence inv-sort-values
+ 1 check-bounds [ second-unsafe ] inv-sort-by ;
+
+M: hashtable inv-sort-values
+ >alist [ { array } declare second-unsafe ] inv-sort-by ;
swap >>error ; inline
: sort-errors ( errors -- alist )
- [ [ line#>> 0 or ] sort-with ] { } assoc-map-as sort-keys ;
+ [ [ line#>> 0 or ] sort-by ] { } assoc-map-as sort-keys ;
: group-by-source-file ( errors -- assoc )
[ path>> ] collect-by ;
ERROR: no-word-error name ;
: word-restarts ( possibilities -- restarts )
- natural-sort [
+ sort [
[ vocabulary>> "Use the " " vocabulary" surround ] keep
] { } map>assoc ;
ERROR: no-vocab name ;
: loaded-vocab-names ( -- seq )
- dictionary get keys natural-sort ;
+ dictionary get keys sort ;
: vocab-words ( vocab-spec -- seq )
vocab-words-assoc values ;
] bi* ;
: (fortran-in-shuffle) ( ret par -- seq )
- [ second ] sort-with append ;
+ [ second ] sort-by append ;
: (fortran-out-shuffle) ( ret par -- seq )
append ;
IN: anagrams
: make-anagram-hash ( strings -- assoc )
- [ natural-sort ] collect-by
+ [ sort ] collect-by
[ members ] assoc-map
[ nip length 1 > ] assoc-filter ;
dict-words make-anagram-hash ;
: anagrams ( str -- seq/f )
- >lower natural-sort dict-anagrams at ;
+ >lower sort dict-anagrams at ;
: most-anagrams ( -- seq )
dict-anagrams values all-longest ;
{
"The " { $vocab-link "annotations" } " vocabulary provides syntax for comment-like annotations that can be looked up with Factor's " { $link usage } " mechanism."
}
-annotation-tags natural-sort
+annotation-tags sort
[
[ \ $subsection swap comment-word 2array ] map append
"To look up annotations:" suffix
IN: benchmark.interval-sets
: interval-sets-benchmark ( -- )
- 10,000 [ random-32 ] replicate natural-sort
+ 10,000 [ random-32 ] replicate sort
2 <groups> <interval-set>
3,000,000 swap '[ random-32 _ interval-in? drop ] times ;
CONSTANT: alist-to-sort $[ 1,000 <iota> dup zip ]
: sort-benchmark ( -- )
- 10 [ numbers-to-sort natural-sort drop ] times
+ 10 [ numbers-to-sort sort drop ] times
5,000 [ alist-to-sort sort-keys drop ] times ;
MAIN: sort-benchmark
: splay-benchmark ( -- )
100,000 initial-alist 10,000 cut
[ >splay ] [ randomize 10,000 head ] bi
- change-random keys dup natural-sort assert= ;
+ change-random keys dup sort assert= ;
MAIN: splay-benchmark
html.parser.analyzer http.client io.backend io.directories
io.encodings.utf8 io.files io.files.temp io.launcher
io.pathnames kernel multiline qw sequences sorting.human
-sorting.slots windows.shell32 ;
+windows.shell32 ;
IN: build-from-source.windows
! choco install -y meson StrawberryPerl nasm winflexbison3 glfw3
! See https://factorcode.org/license.txt for BSD license.
USING: accessors combinators combinators.short-circuit kernel
math.order ranges sequences sequences.generalizations
-sequences.parser sorting.functor sorting.slots unicode ;
+sequences.parser sorting unicode ;
IN: c.lexer
: take-c-comment ( sequence-parser -- seq/f )
: take-c-identifier ( sequence-parser -- string/f )
[ (take-c-identifier) ] with-sequence-parser ;
-<< "length" [ length ] define-sorting >>
-
-: sort-tokens ( seq -- seq' )
- { length>=< <=> } sort-by ;
+: sort-tokens ( seq -- seq' ) [ length ] inv-sort-by ;
: take-c-integer ( sequence-parser -- string/f )
[
dup detect-file dup binary?
[ f ] [ 2dup dupd first-line find-mode ] if
code-file boa
- ] map [ mode>> ] filter [ name>> ] sort-with ;
+ ] map [ mode>> ] filter [ name>> ] sort-by ;
: html-name-char ( char -- str )
{
[ html-name-char ] { } map-as concat ".html" append ;
: toc-list ( files -- list )
- [ name>> ] map natural-sort [
+ [ name>> ] map sort [
[ file-html-name ] keep
[XML <li><a href=<->><-></a></li> XML]
] map ;
! Copyright (C) 2009 Slava Pestov.
! See https://factorcode.org/license.txt for BSD license.
USING: accessors colors combinators combinators.smart formatting
-kernel literals math math.functions models sorting.human
-sorting.slots strings ui ui.gadgets.scrollers
-ui.gadgets.search-tables ui.gadgets.tables ;
+kernel literals math math.functions models sorting.human strings
+ui ui.gadgets.scrollers ui.gadgets.search-tables
+ui.gadgets.tables ;
IN: color-table
! ui.gadgets.tables demo
drop named-color ;
: <color-table> ( -- table )
- named-colors { humani<=> } sort-by <model>
+ named-colors humani-sort <model>
color-renderer
[ ] <search-table> dup table>>
5 >>gap
nl
"Commands available:" print
"===================" print
- nip commands>> [ name>> ] map natural-sort
+ nip commands>> [ name>> ] map sort
[ 6 <groups> ] [ longest length 4 + ] bi
'[ [ _ CHAR: \s pad-tail write ] each nl ] each nl
] [
] if ;
: gvns ( -- str )
- vregs>vns get >alist natural-sort [
+ vregs>vns get >alist sort [
first2 value-mapping
] map "" concat-as ;
] keep ;
: congruence-classes ( -- str )
- vregs>vns get invert-assoc >alist natural-sort [
+ vregs>vns get invert-assoc >alist sort [
first2
- natural-sort [ number>string ] map ", " join
+ sort [ number>string ] map ", " join
over exprs>vns get value-at expr>str
"<%d> : {%s} (%s)\\l" sprintf
] map "" concat-as ;
: contributors ( -- )
changelog histogram merge-aliases
- sort-values <reversed>
+ inv-sort-values
simple-table. ;
MAIN: contributors
[
H{ { "roses" "lutefisk" } { "tulips" "lox" } }
[ ": " glue , ] assoc-each
- ] { } make natural-sort
+ ] { } make sort
] unit-test
{ { "roses: lutefisk" "tulips: lox" } }
[
H{ { "roses" "lutefisk" } { "tulips" "lox" } }
- [ ": " glue ] { } assoc>map natural-sort
+ [ ": " glue ] { } assoc>map sort
] unit-test
: compile-test-each ( xs -- )
{ { "roses: lutefisk" "tulips: lox" } }
[
[ H{ { "roses" "lutefisk" } { "tulips" "lox" } } compile-test-assoc-each ]
- { } make natural-sort
+ { } make sort
] unit-test
{ { "roses: lutefisk" "tulips: lox" } }
[
H{ { "roses" "lutefisk" } { "tulips" "lox" } } compile-test-assoc>map
- natural-sort
+ sort
] unit-test
IN: did-you-mean
: did-you-mean-restarts ( possibilities -- restarts )
- natural-sort
+ sort
[ [ [ vocabulary>> ] [ name>> ] bi "Use %s:%s" sprintf ] keep ]
{ } map>assoc ;
USING: enigma kernel math sequences sorting tools.test ;
-{ t } [ <reflector> natural-sort 26 <iota> sequence= ] unit-test
+{ t } [ <reflector> sort 26 <iota> sequence= ] unit-test
{ "" } [ "" 4 <enigma> encode ] unit-test
[ word? ] filter [ word>xref ] map ;
: group-xrefs ( xrefs -- xrefs' )
- natural-sort [ second ] collect-by
+ sort [ second ] collect-by
! Change key from 'name' to { name path }
[ [ [ third ] map-find drop 2array ] keep ] assoc-map
- >alist natural-sort ;
+ >alist sort ;
: filter-prefix ( seq prefix -- seq )
[ drop-prefix nip empty? ] curry filter members ;
: get-vocabs/prefix ( prefix -- seq ) all-disk-vocab-names swap filter-prefix ;
: get-vocabs-words/prefix ( prefix names/f -- seq )
- [ vocabs-words ] [ current-words ] if* natural-sort swap filter-prefix ;
+ [ vocabs-words ] [ current-words ] if* sort swap filter-prefix ;
path [
[ name>> "." head? ] reject
[ { [ directory? ] [ regular-file? ] } 1|| ] filter
- [ name>> ] sort-with
+ [ name>> ] sort-by
[
[ name>> ] [ directory? [ "/" append ] when ] bi
[
GML:: subarray ( array n k -- slice )
k n k + array subseq ;
GML: sort-number-permutation ( array -- permutation )
- zip-index sort-keys reverse values ;
+ zip-index sort-keys <reversed> values ;
! Dictionaries
ERROR: not-a-dict object ;
path [
[ name>> "." head? ] reject
[ { [ directory? ] [ regular-file? ] } 1|| ] filter
- [ name>> ] sort-with
+ [ name>> ] sort-by
[
[ gopher-type ] [ name>> ] [ directory? [ "/" append ] when ] tri
[
[ [ length ] [ c:int >c-array ] bi glDrawBuffers ] if ;
: bind-named-output-attachments ( program-instance framebuffer attachments -- )
- rot '[ first _ swap output-index ] sort-with values
+ rot '[ first _ swap output-index ] sort-by values
bind-unnamed-output-attachments ;
: bind-output-attachments ( program-instance framebuffer attachments -- )
{ f } [ \ a-defined-word empty-examples? ] unit-test
{ f } [ \ keep empty-examples? ] unit-test
-{ { $description $values } } [ \ an-empty-word-with-a-unique-name missing-sections natural-sort ] unit-test
-{ { $description $values } } [ \ a-defined-word missing-sections natural-sort ] unit-test
+{ { $description $values } } [ \ an-empty-word-with-a-unique-name missing-sections sort ] unit-test
+{ { $description $values } } [ \ a-defined-word missing-sections sort ] unit-test
{ { } } [ \ keep missing-sections ] unit-test
{ { "a.b" "a.b.c" } } [ { "a.b" "a.b.private" "a.b.c.private" "a.b.c" } filter-private ] unit-test
} case ;
: sorted-loaded-child-vocabs ( prefix -- assoc )
- loaded-child-vocab-names natural-sort ; inline
+ loaded-child-vocab-names sort ; inline
: filter-private ( seq -- no-private )
[ ".private" ?tail nip ] reject ; inline
: <vocab-help-coverage> ( vocab-spec -- coverage )
dup loaded-vocab? [
- [ auto-use? off vocab-words natural-sort [ <word-help-coverage> ] map ] with-scope
+ [ auto-use? off vocab-words sort [ <word-help-coverage> ] map ] with-scope
] [
unloaded-vocab
] if ;
{ void* } [ getifaddrs io-error ] with-out-parameters
&freeifaddrs ifaddrs deref
[ ifa_next>> ] follow
- [ ifa_name>> ] map members natural-sort
+ [ ifa_name>> ] map members sort
] with-destructors ;
stripe-height ;
:: (pack-images) ( images atlas-width sort-quot -- placements )
- images sort-quot inv-sort-with [ f image-placement boa ] map :> image-placements
+ images sort-quot inv-sort-by [ f image-placement boa ] map :> image-placements
0 :> @y!
[ image-placements atlas-width @y (pack-stripe) ] [ @y + @y! ] while*
image-placements ; inline
] if ;
: permutation ( seq -- perm )
- [ natural-sort ] keep [ index ] curry map ;
+ [ sort ] keep [ index ] curry map ;
: (inversions) ( n seq -- n )
[ > ] with count ;
2drop 0 { }
] [
dup permutation inversions -1^ rot *
- swap natural-sort
+ swap sort
] if ;
: wedge ( x y -- x.y )
] map sift 2nip ;
: basis ( generators -- seq )
- natural-sort dup length 2^ <iota> [ nth-basis-elt ] with map ;
+ sort dup length 2^ <iota> [ nth-basis-elt ] with map ;
: (tensor) ( seq1 seq2 -- seq )
[
- [ prepend natural-sort ] curry map
+ [ prepend sort ] curry map
] with map concat ;
: tensor ( graded-basis1 graded-basis2 -- bigraded-basis )
: find-unused-in-string ( string -- seq )
strip-code [ get-imported-words ] [ find-used-words ] bi
- reject-unused-vocabs natural-sort ;
+ reject-unused-vocabs sort ;
: find-unused-in-file ( path -- seq )
utf8 file-contents find-unused-in-string ;
: find-unused. ( name -- )
dup find-unused dup empty?
[ print-no-unused-vocabs ]
- [ print-unused-vocabs ] if ;
\ No newline at end of file
+ [ print-unused-vocabs ] if ;
3 3 pick set-at
4 4 pick set-at
5 5 pick set-at
- >alist natural-sort
+ >alist sort
] unit-test
{
1 over at drop
4 4 pick set-at
5 5 pick set-at
- >alist natural-sort
+ >alist sort
] unit-test
{
2 over at drop
4 4 pick set-at
5 5 pick set-at
- >alist natural-sort
+ >alist sort
] unit-test
{
3 3 pick set-at
4 4 pick set-at
5 5 pick set-at
- >alist natural-sort
+ >alist sort
] unit-test
{
1 1 pick set-at
4 4 pick set-at
5 5 pick set-at
- >alist natural-sort
+ >alist sort
] unit-test
{
3 3 pick set-at
4 4 pick set-at
5 5 pick set-at
- >alist natural-sort
+ >alist sort
] unit-test
{
1 over delete-at
4 4 pick set-at
5 5 pick set-at
- >alist natural-sort
+ >alist sort
] unit-test
normalized-histogram values entropy 2 log / ;
: group-by-sorted ( seq quot: ( elt -- key ) -- groups )
- [ sort-with ] keep group-by ; inline
+ [ sort-by ] keep group-by ; inline
: subsets-weighted-entropy ( data-target idx -- seq )
! Group the data according to the given index.
label-binarizer new ; inline
M: label-binarizer fit-y
- [ members natural-sort ] dip classes_<< ;
+ [ members sort ] dip classes_<< ;
M: label-binarizer transform-y
classes_>> dup length '[
: <label-encoder> ( -- le ) label-encoder new ; inline
M: label-encoder fit-y ( y transformer -- )
- [ members natural-sort ] dip classes_<< ;
+ [ members sort ] dip classes_<< ;
M: label-encoder transform-y ( y transformer -- y' )
classes_>> '[ _ bisect-left ] map ;
: handle-help ( string -- )
[
"Commands: "
- commands get keys natural-sort ", " join append send-line
+ commands get keys sort ", " join append send-line
] [
chat-docs get ?at
[ send-line ]
:: do-step ( errors summary-file details-file -- )
errors
[ error-type +linkage-error+ eq? ] reject
- [ path>> ] map members natural-sort summary-file to-file
+ [ path>> ] map members sort summary-file to-file
errors details-file utf8 [ errors. ] with-file-writer ;
: do-tests ( -- )
<PRIVATE
:: (gini) ( seq -- x )
- seq natural-sort :> sorted
+ seq sort :> sorted
seq length :> len
sorted 0 [ + ] cum-reduce :> ( a b )
b len a * / :> c
! Semi-efficient versions of Burrows-Wheeler Transform
:: bwt ( seq -- i newseq )
- seq all-rotations natural-sort
+ seq all-rotations sort
[ [ n>> 0 = ] find drop ] keep
[ last ] seq map-as ;
[ "5" x m/set ] with-memcached
[ "valuex" y m/set ] with-memcached
{ { "5" "valuex" } } [
- [ x y z 3array m/getseq values natural-sort ] with-memcached
+ [ x y z 3array m/getseq values sort ] with-memcached
] unit-test
[ [ canonicalize-specializer-1 ] dip ] assoc-map
- hooks [ natural-sort ] change
+ hooks [ sort ] change
[ [ canonicalize-specializer-2 ] dip ] assoc-map
: sorted-pair-methods ( word -- alist )
"pair-generic-methods" word-prop >alist
- [ first method-sort-key ] inv-sort-with ;
+ [ first method-sort-key ] inv-sort-by ;
: pair-generic-definition ( word -- def )
[ sorted-pair-methods [ first2 pair-method-cond ] map ]
: order-slabs ( slabs eye -- slabs' )
! NO
- ! '[ center>> _ v- norm-sq ] inv-sort-with ; inline
+ ! '[ center>> _ v- norm-sq ] inv-sort-by ; inline
drop ;
: render-slabs ( slabs -- vertices indexes )
"" 2sequence H{ { "AB" 1 } { "AD" 2 } { "BC" 5 } { "DC" 2 } { "DE" 1 } { "EC" 2 } { "EF" 1 } } at ;
: test2 ( fromto -- path considered )
- first2 [ n ] [ c ] [ 2drop 0 ] <astar> [ find-path ] [ considered natural-sort >string ] bi ;
+ first2 [ n ] [ c ] [ 2drop 0 ] <astar> [ find-path ] [ considered sort >string ] bi ;
>>
! Check path from A to C -- all nodes but F must have been examined
routes keys [ dup dup n [ dup [ c ] dip swap 2array ] with { } map-as >hashtable 2array ] map >hashtable ;
: test3 ( fromto -- path considered )
- first2 costs <dijkstra> [ find-path ] [ considered natural-sort >string ] bi ;
+ first2 costs <dijkstra> [ find-path ] [ considered sort >string ] bi ;
>>
100 999 [a..b] [ 10 divisor? ] reject ;
: max-palindrome ( seq -- palindrome )
- natural-sort [ palindrome? ] find-last nip ;
+ sort [ palindrome? ] find-last nip ;
PRIVATE>
[ sq ] bi@
[ - 2 / , ] ! b = (p² - q²) / 2
[ + 2 / , ] 2bi ! c = (p² + q²) / 2
- ] { } make natural-sort ;
+ ] { } make sort ;
: (ptriplet) ( target p q triplet -- target p q )
sum pickd = [ next-pq 2dup abc (ptriplet) ] unless ;
PRIVATE>
: euler022 ( -- answer )
- source-022 natural-sort name-scores sum ;
+ source-022 sort name-scores sum ;
! [ euler022 ] 100 ave-time
! 74 ms ave run time - 5.13 SD (100 trials)
[ unclip 1 head prefix concat ] map [ all-unique? ] filter ;
: add-missing-digit ( seq -- seq )
- dup natural-sort 10 <iota> swap diff prepend ;
+ dup sort 10 <iota> swap diff prepend ;
: interesting-pandigitals ( -- seq )
17 candidates { 13 11 7 5 3 2 } [
<iota> [ 1 + * ] with map ; inline
: all-same-digits? ( seq -- ? )
- [ number>digits natural-sort ] map all-equal? ;
+ [ number>digits sort ] map all-equal? ;
: candidate? ( n -- ? )
{ [ odd? ] [ 3 divisor? ] } 1&& ;
<PRIVATE
: cube ( n -- n^3 ) 3 ^ ; inline
-: >key ( n -- k ) cube number>digits natural-sort ; inline
+: >key ( n -- k ) cube number>digits sort ; inline
: has-entry? ( n assoc -- ? ) [ >key ] dip key? ; inline
: (euler062) ( n assoc -- n )
<PRIVATE
: bouncy? ( n -- ? )
- number>digits dup natural-sort
+ number>digits dup sort
[ = not ] [ reverse = not ] 2bi and ;
PRIVATE>
number>string dup reverse = ;
: pandigital? ( n -- ? )
- number>string natural-sort >string "123456789" = ;
+ number>string sort >string "123456789" = ;
: pentagonal? ( n -- ? )
dup 0 > [ 24 * 1 + sqrt 1 + 6 / 1 mod zero? ] [ drop f ] if ; inline
] while BASE delta * delta SKEW + /i + ;
: segregate ( str -- base extended )
- [ N < ] partition members natural-sort ;
+ [ N < ] partition members sort ;
:: find-pos ( str ch i pos -- i' pos' )
i pos 1 + str [
"c" { -0.5 -0.75 } value>>key
"d" { 0.75 0.25 } value>>key
- { -0.6 -0.8 } { 0.8 1.0 } <rect> swap in-rect natural-sort
+ { -0.6 -0.8 } { 0.8 1.0 } <rect> swap in-rect sort
] unit-test
{ T{ quadtree f T{ rect f { -1.0 -1.0 } { 2.0 2.0 } } f f
"g" { 0.25 0.25 } value>>key
"h" { 0.75 0.75 } value>>key
- >alist natural-sort
+ >alist sort
] unit-test
TUPLE: pointy-thing center ;
{ { "aa" "ab" "ac" } } [
[
{ "aa" "ab" "ac" "bd" } [ "hello" swap redis-set ] each
- "a*" redis-keys natural-sort
+ "a*" redis-keys sort
] with-redis-test
] unit-test
: noisy-words ( -- alist )
all-words flatten-generics
[ word-noise-factor ] zip-with
- sort-values reverse ;
+ inv-sort-values ;
: noise. ( alist -- )
standard-table-style [
: noisy-vocabs ( -- alist )
loaded-vocab-names [ vocab-noise-factor ] zip-with
- sort-values reverse ;
+ inv-sort-values ;
: noise-report ( -- )
"NOISY WORDS:" print
utf8 file-lines
H{ } clone [
'[
- [ natural-sort >string ] keep
+ [ sort >string ] keep
_ [ swap suffix ] with change-at
] each
] keep ;
parse-dict-file anagrams [ derangements ] map concat ;
: (longest-deranged-anagrams) ( path -- anagrams )
- deranged-anagrams [ first length ] sort-with last ;
+ deranged-anagrams [ first length ] sort-by last ;
: default-word-list ( -- path )
URL" https://puzzlers.org/pub/wordlists/unixdict.txt"
! How many ways can we make the given amount of cents
! with the given set of coins?
: make-change ( cents coins -- ways )
- members [ ] inv-sort-with (make-change) ;
+ members inv-sort (make-change) ;
solve-knapsack
"Total value: " write number>string print
"Items packed: " print
- natural-sort
+ sort
[ " " write print ] each ;
MAIN: knapsack-main
: prepare-departments ( seq -- departments )
[ department>> ] collect-by
- [ [ salary>> ] inv-sort-with ] assoc-map ;
+ [ [ salary>> ] inv-sort-by ] assoc-map ;
: first-n-each ( seq n quot -- )
[ index-or-length head-slice ] dip each ; inline
USING: accessors assocs base64 calendar calendar.format
calendar.parser checksums.hmac checksums.sha combinators http
http.client kernel make math.order namespaces sequences
-sorting sorting.slots strings xml xml.traversal ;
+sorting strings xml xml.traversal ;
IN: s3
SYMBOL: key-id
: hashtable>headers ( hashtable -- seq )
[
[ swap % ":" % % "\n" % ] "" make
- ] { } assoc>map [ <=> ] sort ;
+ ] { } assoc>map sort ;
: signature ( s3-request -- string )
[
f "/" H{ } clone s3-get nip >string string>xml (buckets) ;
: sorted-buckets ( -- seq )
- buckets { { date>> rfc3339>timestamp <=> } } sort-by ;
+ buckets [ date>> rfc3339>timestamp ] sort-by ;
<PRIVATE
: bucket-url ( bucket -- string )
"2.0.0"
"2.1.0"
"2.1.1"
- } dup clone randomize [ semver<=> ] sort =
+ } dup clone randomize [ semver<=> ] sort-with =
] unit-test
[ dir>> move-loc ] accumulate nip ;
: snake-occupied-indices ( snake head-loc -- points )
- snake-occupied-locs [ game-loc>index ] map natural-sort ;
+ snake-occupied-locs [ game-loc>index ] map sort ;
: snake-unoccupied-indices ( snake head-loc -- points )
[ all-indices ] 2dip snake-occupied-indices without ;
USING: kernel sorting.bubble tools.test ;
-{ { } } [ { } dup natural-bubble-sort! ] unit-test
-{ { 1 } } [ { 1 } dup natural-bubble-sort! ] unit-test
-{ { 1 2 3 4 5 } } [ { 1 4 2 5 3 } dup natural-bubble-sort! ] unit-test
+{ { } } [ { } dup bubble-sort! ] unit-test
+{ { 1 } } [ { 1 } dup bubble-sort! ] unit-test
+{ { 1 2 3 4 5 } } [ { 1 4 2 5 3 } dup bubble-sort! ] unit-test
<PRIVATE
-:: (bubble-sort!) ( seq quot: ( obj1 obj2 -- <=> ) -- )
+:: (bubble-sort-with!) ( seq quot: ( obj1 obj2 -- <=> ) -- )
seq length 1 - [
f over [0..b) [| i |
i i 1 + [ seq nth-unsafe ] bi@ 2dup quot call +gt+ =
PRIVATE>
-: bubble-sort! ( seq quot: ( obj1 obj2 -- <=> ) -- )
- over length 2 < [ 2drop ] [ (bubble-sort!) ] if ; inline
+: bubble-sort-with! ( seq quot: ( obj1 obj2 -- <=> ) -- )
+ over length 2 < [ 2drop ] [ (bubble-sort-with!) ] if ; inline
-: natural-bubble-sort! ( seq -- )
- [ <=> ] bubble-sort! ;
+: bubble-sort! ( seq -- ) [ <=> ] bubble-sort-with! ;
: argsort ( seq quot: ( obj1 obj2 -- <=> ) -- sortedseq )
[ zip-index ] dip
[ [ first-unsafe ] bi@ ] prepose
- sort [ second-unsafe ] map! ; inline
+ sort-with [ second-unsafe ] map! ; inline
: map-sort ( ... seq quot: ( ... elt -- ... key ) -- ... sortedseq )
[ keep ] curry { } map>assoc
- [ { array } declare first-unsafe ] sort-with
+ [ { array } declare first-unsafe ] sort-by
[ { array } declare second-unsafe ] map ; inline
:: bisect-left ( obj seq -- i )
USING: kernel sequences sorting.quick tools.test ;
-{ { } } [ { } dup natural-sort! ] unit-test
-{ { 1 } } [ { 1 } dup natural-sort! ] unit-test
-{ { 1 2 3 4 5 } } [ { 1 4 2 5 3 } dup natural-sort! ] unit-test
+{ { } } [ { } dup sort! ] unit-test
+{ { 1 } } [ { 1 } dup sort! ] unit-test
+{ { 1 2 3 4 5 } } [ { 1 4 2 5 3 } dup sort! ] unit-test
{
{ "dino" "fred" "wilma" "betty" "barney" "pebbles" "bamm-bamm" }
} [
{ "fred" "wilma" "pebbles" "dino" "barney" "betty" "bamm-bamm" }
- dup [ length ] sort-with!
+ dup [ length ] sort-by!
] unit-test
PRIVATE>
-: sort! ( seq quot: ( obj1 obj2 -- <=> ) -- )
+: sort-with! ( seq quot: ( obj1 obj2 -- <=> ) -- )
[ 0 over length check-array-capacity 1 - ] dip quicksort ; inline
-: sort-with! ( seq quot: ( elt -- key ) -- )
- [ compare ] curry sort! ; inline
+: inv-sort-with! ( seq quot: ( obj1 obj2 -- <=> ) -- )
+ '[ @ invert-comparison ] sort-with! ; inline
-: inv-sort-with! ( seq quot: ( elt -- key ) -- )
- [ compare invert-comparison ] curry sort! ; inline
+: sort-by! ( seq quot: ( elt -- key ) -- )
+ [ compare ] curry sort-with! ; inline
-GENERIC: natural-sort! ( seq -- )
+: inv-sort-by! ( seq quot: ( elt -- key ) -- )
+ [ compare invert-comparison ] curry sort-with! ; inline
-M: object natural-sort! [ <=> ] sort! ;
-M: array natural-sort! [ <=> ] sort! ;
-M: vector natural-sort! [ <=> ] sort! ;
-M: string natural-sort! [ <=> ] sort! ;
+GENERIC: sort! ( seq -- )
+
+M: object sort! [ <=> ] sort-with! ;
+M: array sort! [ <=> ] sort-with! ;
+M: vector sort! [ <=> ] sort-with! ;
+M: string sort! [ <=> ] sort-with! ;
+
+GENERIC: inv-sort! ( seq -- )
+
+M: object inv-sort! [ <=> ] inv-sort-with! ;
+M: array inv-sort! [ <=> ] inv-sort-with! ;
+M: vector inv-sort! [ <=> ] inv-sort-with! ;
+M: string inv-sort! [ <=> ] inv-sort-with! ;
word 1array dictionary filter-known
[ word edits1 dictionary filter-known ] when-empty
[ word edits2 dictionary filter-known ] when-empty
- [ dictionary at ] sort-with reverse! ;
+ [ dictionary at ] sort-by reverse! ;
: words ( string -- words )
>lower [ letter? not ] split-when harvest ;
:: write-tree ( path indents -- )
path [
- [ name>> ] sort-with [ ] [
+ [ name>> ] sort-by [ ] [
unclip-last [
f indents push
[ indents write-entry ] each
: <dimensioned> ( n top bot -- obj )
symbolic-reduce
- [ natural-sort ] bi@
+ [ sort ] bi@
dimensioned boa ;
: >dimensioned< ( d -- n top bot )
>>comments ;
: reverse-chronological-order ( seq -- sorted )
- [ date>> ] inv-sort-with ;
+ [ date>> ] inv-sort-by ;
: validate-author ( -- )
{ { "author" [ v-username ] } } validate-params ;
} cond ;
: builder-list ( seq -- xml )
- [ os/cpu ] sort-with
+ [ os/cpu ] sort-by
[
[ report-url ] [ os/cpu ] [ builder-status ] tri
[XML <li><a href=<->><-></a> <-></li> XML]
: pastes ( -- pastes )
f <paste-state> select-tuples
- [ date>> ] sort-with
+ [ date>> ] sort-by
reverse ;
TUPLE: annotation < entity parent ;
: blogroll ( -- seq )
f <blog> select-tuples
- [ name>> ] sort-with ;
+ [ name>> ] sort-by ;
: postings ( -- seq )
posting new select-tuples
- [ date>> ] inv-sort-with ;
+ [ date>> ] inv-sort-by ;
: <edit-blogroll-action> ( -- action )
<page-action>
[ '[ _ <posting> ] map ] 2map concat ;
: sort-entries ( entries -- entries' )
- [ date>> ] inv-sort-with ;
+ [ date>> ] inv-sort-by ;
: update-cached-postings ( -- )
blogroll fetch-blogroll sort-entries 8 index-or-length head [
M: revision feed-entry-url id>> revision-url ;
: reverse-chronological-order ( seq -- sorted )
- [ date>> ] inv-sort-with ;
+ [ date>> ] inv-sort-by ;
: <revision> ( id -- revision )
revision new swap >>id ;
[
f <article> select-tuples
- [ title>> ] sort-with
+ [ title>> ] sort-by
"articles" set-value
] >>init
[ f ] [
f <article> select-tuples
- [ title>> ] sort-with
+ [ title>> ] sort-by
[ revision>> <revision> select-tuple ] map
swap '[ content>> _ [ first-match ] with all? ] filter
] if-empty
] with map concat members
[ background of ] assoc-map
[ drop ] collect-value-by
- [ [ color>n ] zip-with sort-values reverse first first ] assoc-map
+ [ [ color>n ] zip-with sort-values <reversed> first first ] assoc-map
CHAR: a CHAR: z [a..b] [ 1string COLOR: white ] { } map>assoc [ or ] assoc-merge ;
: print-remaining-chars ( game -- )
*wordtimes* [ (correct-for-timing-overhead) ] change-global ;
: print-word-timings ( -- )
- *wordtimes* get-global [ swap suffix ] { } assoc>map natural-sort reverse pprint ;
+ *wordtimes* get-global [ swap suffix ] { } assoc>map inv-sort pprint ;
: wordtimer-call ( quot -- )
reset-word-timer
: zoneinfo-zones ( -- seq )
raw-zone-map keys
[ "/" subseq-of? ] partition
- [ natural-sort ] bi@ append ;
+ [ sort ] bi@ append ;
GENERIC: zone-matches? ( string rule -- ? )
" Vim syntax file
" Language: Factor
" Maintainer: Alex Chapman <chapman.alex@gmail.com>
-" Last Change: 2022 Aug 06
+" Last Change: 2023 Feb 08
" Minimum Version: 600
" To regenerate: USE: editors.vim.generate-syntax generate-vim-syntax
SynKeywordFactorWord factorWord_alien | syn keyword factorWord_alien contained <alien> <bad-alien> <callback> <displaced-alien> >c-ptr abi abi? alien alien-address alien-assembly alien-callback alien-indirect alien-invoke alien? binary-object byte-length c-ptr c-ptr? callee-cleanup? callsite-not-compiled callsite-not-compiled? cdecl cdecl? dll dll? element-size expired? fastcall fastcall? free-callback initialize-alien mingw mingw? pinned-alien pinned-alien? pinned-c-ptr pinned-c-ptr? stdcall stdcall? thiscall thiscall? unregister-and-free-callback with-callback
SynKeywordFactorWord factorWord_arrays | syn keyword factorWord_arrays contained 1array 2array 3array 4array <array> >array array array? pair pair? resize-array
-SynKeywordFactorWord factorWord_assocs | syn keyword factorWord_assocs contained 2cache <enumerated> >alist ?at ?change-at ?delete-at ?of ?value-at assoc assoc-all? assoc-any? assoc-clone-like assoc-diff assoc-diff! assoc-differ assoc-each assoc-empty? assoc-filter assoc-filter! assoc-filter-as assoc-find assoc-hashcode assoc-intersect assoc-intersect-all assoc-like assoc-map assoc-map-as assoc-partition assoc-reject assoc-reject! assoc-reject-as assoc-size assoc-stack assoc-subset? assoc-union assoc-union! assoc-union-all assoc-union-as assoc= assoc>map assoc? at at* at+ cache change-at clear-assoc collect-by delete-at delete-at* enumerated enumerated? extract-keys harvest-keys harvest-values inc-at key? keys map>alist map>assoc maybe-set-at new-assoc of push-at rename-at set-at sift-keys sift-values substitute unzip value-at value-at* value? values zip zip-as zip-index zip-index-as zip-with zip-with-as
+SynKeywordFactorWord factorWord_assocs | syn keyword factorWord_assocs contained 2cache <enumerated> >alist ?at ?change-at ?delete-at ?of ?value-at assoc assoc-all? assoc-any? assoc-clone-like assoc-diff assoc-diff! assoc-differ assoc-each assoc-empty? assoc-filter assoc-filter! assoc-filter-as assoc-find assoc-hashcode assoc-intersect assoc-intersect-all assoc-like assoc-map assoc-map-as assoc-partition assoc-reject assoc-reject! assoc-reject-as assoc-size assoc-stack assoc-subset? assoc-union assoc-union! assoc-union-all assoc-union-as assoc= assoc>map assoc? at at* at+ cache change-at clear-assoc collect-by collect-by! delete-at delete-at* enumerated enumerated? extract-keys harvest-keys harvest-values inc-at key? keys map>alist map>assoc maybe-set-at new-assoc of push-at rename-at set-at sift-keys sift-values substitute unzip value-at value-at* value? values zip zip-as zip-index zip-index-as zip-with zip-with-as
SynKeywordFactorWord factorWord_byte__arrays | syn keyword factorWord_byte__arrays contained (byte-array) 1byte-array 2byte-array 3byte-array 4byte-array <byte-array> >byte-array byte-array byte-array? byte-sequence byte-sequence? resize-byte-array
SynKeywordFactorWord factorWord_classes | syn keyword factorWord_classes contained all-contained-classes bad-inheritance bad-inheritance? check-instance class class-members class-of class-participants class-usage class-usages class-uses class? classes classoid classoid? contained-classes create-predicate-word define-predicate defining-class defining-class? forget-class implementors instance? not-an-instance not-an-instance? predicate predicate-def predicate-word predicate? subclass-of? superclass-of superclass-of? superclasses-of
SynKeywordFactorWord factorWord_classes_maybe | syn keyword factorWord_classes_maybe contained <maybe> maybe maybe-class-or maybe?
SynKeywordFactorWord factorWord_io_encodings_binary | syn keyword factorWord_io_encodings_binary contained binary binary?
SynKeywordFactorWord factorWord_io_encodings_utf8 | syn keyword factorWord_io_encodings_utf8 contained >utf8-index code-point-length code-point-offsets utf8 utf8-index> utf8?
SynKeywordFactorWord factorWord_io_files | syn keyword factorWord_io_files contained (file-appender) (file-reader) (file-writer) +input+ +output+ +retry+ <file-appender> <file-reader> <file-writer> change-file-contents change-file-lines drain file-contents file-exists? file-lines file-reader file-reader? file-writer file-writer? init-resource-path refill set-file-contents set-file-lines wait-for-fd with-file-appender with-file-reader with-file-writer
-SynKeywordFactorWord factorWord_kernel | syn keyword factorWord_kernel contained (clone) -roll -rot -rotd 2bi 2bi* 2bi@ 2curry 2dip 2drop 2dup 2keep 2keepd 2nip 2nipd 2over 2tri 2tri* 2tri@ 2with 3bi 3curry 3dip 3drop 3dup 3keep 3nip 3nipd 3tri 4dip 4drop 4dup 4keep 4nip 5drop 5nip <wrapper> = >boolean ? ?if and assert assert= assert? bi bi* bi-curry bi-curry* bi-curry@ bi@ boa boolean boolean? both? build call callstack callstack>array callstack? clear clone compose composed composed? curried curried? curry die dip do drop dup dupd either? eq? equal? execute get-callstack get-datastack get-retainstack hashcode hashcode* identity-hashcode identity-tuple identity-tuple? if if* keep keepd keepdd loop most negate new nip nipd not null object or over overd pick pickd prepose reach recursive-hashcode roll rot rotd same? spin swap swapd throw tri tri* tri-curry tri-curry* tri-curry@ tri@ tuck tuple tuple? unless unless* until when when* while while* with withd wrapper wrapper? xor
+SynKeywordFactorWord factorWord_kernel | syn keyword factorWord_kernel contained (clone) -roll -rot -rotd 2bi 2bi* 2bi@ 2curry 2dip 2drop 2dup 2keep 2keepd 2nip 2nipd 2over 2tri 2tri* 2tri@ 2with 3bi 3curry 3dip 3drop 3dup 3keep 3nip 3nipd 3tri 4dip 4drop 4dup 4keep 4nip 5drop 5nip <wrapper> = >boolean ? ?if and assert assert= assert? bi bi* bi-curry bi-curry* bi-curry@ bi@ boa boolean boolean? both? build call callstack callstack>array callstack? clear clone compose composed composed? curried curried? curry die dip do drop dup dupd either? eq? equal? execute get-callstack get-datastack get-retainstack hashcode hashcode* identity-hashcode identity-tuple identity-tuple? if if* keep keepd keepdd loop most negate new nip nipd not null object or over overd pick pickd prepose reach roll rot rotd same? spin swap swapd throw tri tri* tri-curry tri-curry* tri-curry@ tri@ tuck tuple tuple? unless unless* until when when* while while* with withd wrapper wrapper? xor
SynKeywordFactorWord factorWord_layouts | syn keyword factorWord_layouts contained (first-bignum) (fixnum-bits) (max-array-capacity) 32-bit? 64-bit? bootstrap-cell bootstrap-cell-bits bootstrap-cells bootstrap-first-bignum bootstrap-fixnum-bits bootstrap-max-array-capacity bootstrap-most-negative-fixnum bootstrap-most-positive-fixnum cell cell-bits cells data-alignment first-bignum fixnum-bits hashcode-shift header-bits immediate immediate? leaf-stack-frame-size max-array-capacity mega-cache-size most-negative-fixnum most-positive-fixnum num-types tag-bits tag-fixnum tag-header tag-mask type-number type-numbers untag-fixnum
SynKeywordFactorWord factorWord_make | syn keyword factorWord_make contained % %% , ,+ ,, building make
-SynKeywordFactorWord factorWord_math | syn keyword factorWord_math contained * + - / /f /i /mod 2/ 2^ < <= <fp-nan> > >= >bignum >fixnum >float >fraction >integer >rect ?1+ abs align all-integers-from? all-integers? bignum bignum? bit? bitand bitnot bitor bits>double bits>float bitxor complex complex? denominator double>bits each-integer each-integer-from even? find-integer find-integer-from find-last-integer fixnum fixnum? float float>bits float? fp-bitwise= fp-infinity? fp-nan-payload fp-nan? fp-qnan? fp-sign fp-snan? fp-special? gcd if-zero imaginary-part integer integer>fixnum integer>fixnum-strict integer? log2 log2-expects-positive log2-expects-positive? mod neg neg? next-float next-power-of-2 number number= number? numerator odd? power-of-2? prev-float ratio ratio? rational rational? real real-part real? recip rect> rem sgn shift simple-gcd sq times u< u<= u> u>= unless-zero unordered? until-zero when-zero zero?
+SynKeywordFactorWord factorWord_math | syn keyword factorWord_math contained * + - / /f /i /mod 2/ 2^ < <= <fp-nan> > >= >bignum >fixnum >float >fraction >integer >rect ?1+ abs align all-integers-from? all-integers? bignum bignum? bit? bitand bitnot bitor bits>double bits>float bitxor complex complex? denominator double>bits each-integer each-integer-from even? find-integer find-integer-from find-last-integer fixnum fixnum? float float>bits float? fp-bitwise= fp-infinity? fp-nan-payload fp-nan? fp-qnan? fp-sign fp-snan? fp-special? gcd if-zero imaginary-part integer integer>fixnum integer>fixnum-strict integer? log2 log2-expects-positive log2-expects-positive? mod neg neg? next-float next-power-of-2 number number= number? numerator odd? power-of-2? prev-float ratio ratio? rational rational? real real-part real? recip rect> recursive-hashcode rem sgn shift simple-gcd sq times u< u<= u> u>= unless-zero unordered? until-zero when-zero zero?
SynKeywordFactorWord factorWord_math_order | syn keyword factorWord_math_order contained +eq+ +gt+ +lt+ <=> >=< [-] after=? after? before=? before? between? clamp compare invert-comparison max min
SynKeywordFactorWord factorWord_memory | syn keyword factorWord_memory contained all-instances compact-gc gc instances minor-gc save save-image save-image-and-exit saving-path size
SynKeywordFactorWord factorWord_namespaces | syn keyword factorWord_namespaces contained +@ change change-global counter dec get get-global get-namestack global inc init-namestack initialize namespace off on set set-global set-namestack toggle with-global with-scope with-variable with-variables
-SynKeywordFactorWord factorWord_sequences | syn keyword factorWord_sequences contained 1sequence 1surround 1surround-as 2all? 2any? 2each 2each-from 2map 2map-as 2map-reduce 2reduce 2selector 2sequence 3append 3append-as 3each 3map 3map-as 3sequence 4sequence <iota> <repetition> <reversed> <slice> >slice< ?first ?last ?nth ?second ?set-nth accumulate accumulate! accumulate* accumulate*! accumulate*-as accumulate-as all? any? append append! append-as assert-sequence assert-sequence= assert-sequence? binary-reduce bounds-check bounds-check? bounds-error bounds-error? but-last but-last-slice cartesian-each cartesian-find cartesian-map cartesian-product cartesian-product-as change-nth check-slice clone-like collapse-slice collector collector-as collector-for collector-for-as concat concat-as copy count cut cut* cut-slice cut-slice* delete-all delete-slice drop-prefix each each-from each-index empty? exchange filter filter! filter-as find find-from find-index find-index-from find-last find-last-from first first2 first3 first4 flip follow fourth from-tail glue glue-as halves harvest head head* head-slice head-slice* head-to-index head? if-empty immutable immutable-sequence immutable-sequence? immutable? index index-from index-of-last index-or-length index-to-tail indices infimum infimum-by insert-nth interleave iota iota? join join-as last last-index last-index-from length lengthen like longer longer? longest map map! map-as map-find map-find-last map-index map-index-as map-integers map-integers-as map-reduce map-sum max-length member-eq? member? midpoint@ min-length mismatch move new-like new-resizable new-sequence non-negative-integer-expected non-negative-integer-expected? none? nth nths pad-head pad-tail partition pop pop* prefix prepend prepend-as produce produce-as product push push-all push-either push-if reduce reduce-index reject reject! reject-as remove remove! remove-eq remove-eq! remove-nth remove-nth! repetition repetition? replace-slice replicate replicate-as rest rest-slice reverse reverse! reversed reversed? second selector selector-as sequence sequence-hashcode sequence= sequence? set-first set-fourth set-last set-length set-nth set-second set-third shorten shorter shorter? shortest sift slice slice-error slice-error? slice? snip snip-slice subseq subseq-as subseq-index subseq-index-from subseq-of? subseq-start subseq-start-from subseq-starts-at? subseq? suffix suffix! sum sum-lengths supremum supremum-by surround surround-as tail tail* tail-slice tail-slice* tail? third trim trim-head trim-head-slice trim-slice trim-tail trim-tail-slice unclip unclip-last unclip-last-slice unclip-slice unless-empty virtual-exemplar virtual-sequence virtual-sequence? virtual@ when-empty
+SynKeywordFactorWord factorWord_sequences | syn keyword factorWord_sequences contained 1sequence 1surround 1surround-as 2all? 2any? 2each 2each-from 2map 2map-as 2map-reduce 2reduce 2selector 2sequence 3append 3append-as 3each 3map 3map-as 3sequence 4sequence <iota> <repetition> <reversed> <slice> >slice< ?first ?last ?nth ?second ?set-nth accumulate accumulate! accumulate* accumulate*! accumulate*-as accumulate-as all? any? append append! append-as assert-sequence assert-sequence= assert-sequence? binary-reduce bounds-check bounds-check? bounds-error bounds-error? but-last but-last-slice cartesian-each cartesian-find cartesian-map cartesian-product cartesian-product-as change-nth check-slice clone-like collapse-slice collector collector-as collector-for collector-for-as concat concat-as copy count cut cut* cut-slice cut-slice* delete-all delete-slice drop-prefix each each-from each-index empty? exchange filter filter! filter-as find find-from find-index find-index-from find-last find-last-from first first2 first3 first4 flip follow fourth from-tail glue glue-as halves harvest head head* head-slice head-slice* head-to-index head? if-empty immutable immutable-sequence immutable-sequence? immutable? index index-from index-of-last index-or-length index-to-tail indices infimum infimum-by insert-nth interleave iota iota? join join-as last last-index last-index-from length lengthen like longer longer? longest map map! map-as map-find map-find-last map-index map-index-as map-integers map-integers-as map-integers-from-as map-reduce map-sum max-length member-eq? member? midpoint@ min-length mismatch move new-like new-resizable new-sequence non-negative-integer-expected non-negative-integer-expected? none? nth nths pad-head pad-tail partition pop pop* prefix prepend prepend-as produce produce-as product push push-all push-either push-if reduce reduce-index reject reject! reject-as remove remove! remove-eq remove-eq! remove-nth remove-nth! repetition repetition? replace-slice replicate replicate-as rest rest-slice reverse reverse! reversed reversed? second selector selector-as sequence sequence-hashcode sequence= sequence? set-first set-fourth set-last set-length set-nth set-second set-third shorten shorter shorter? shortest sift slice slice-error slice-error? slice? snip snip-slice subseq subseq-as subseq-index subseq-index-from subseq-of? subseq-start subseq-start-from subseq-starts-at? subseq? suffix suffix! sum sum-lengths supremum supremum-by surround surround-as tail tail* tail-slice tail-slice* tail? third trim trim-head trim-head-slice trim-slice trim-tail trim-tail-slice unclip unclip-last unclip-last-slice unclip-slice unless-empty virtual-exemplar virtual-sequence virtual-sequence? virtual@ when-empty
SynKeywordFactorWord factorWord_sets | syn keyword factorWord_sets contained ?adjoin ?delete adjoin adjoin-all adjoin-at all-unique? cardinality clear-set delete diff diff! duplicates fast-set gather in? intersect intersect! intersect-all intersects? members null? set set-like set= set? subset? union union! union-all within without
-SynKeywordFactorWord factorWord_sorting | syn keyword factorWord_sorting contained compare-with inv-sort-with natural-sort sort sort-keys sort-pair sort-values sort-with
+SynKeywordFactorWord factorWord_sorting | syn keyword factorWord_sorting contained inv-sort inv-sort-by inv-sort-keys inv-sort-values inv-sort-with sort sort-by sort-keys sort-pair sort-values sort-with
SynKeywordFactorWord factorWord_splitting | syn keyword factorWord_splitting contained ?head ?head-slice ?snip ?snip-slice ?tail ?tail-slice join-lines join-lines-as join-words join-words-as replace split split-indices split-lines split-slice split-subseq split-when split-when-slice split-words split1 split1-last split1-last-slice split1-slice split1-when split1-when-slice string-lines subseq-range
SynKeywordFactorWord factorWord_strings | syn keyword factorWord_strings contained 1string <string> >string resize-string string string?
SynKeywordFactorWord factorWord_strings_parser | syn keyword factorWord_strings_parser contained bad-escape bad-escape? escape name>char-hook parse-string unescape-string