From: Doug Coleman Date: Sun, 5 Feb 2023 19:12:09 +0000 (-0600) Subject: factor: rename count-by back to count. count* -> percent-of X-Git-Tag: 0.99~573 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=099aff224dcdcfdab836e064c868fa58c368054b factor: rename count-by back to count. count* -> percent-of count is way more useful as a combinator than as [ ] count-by. --- diff --git a/basis/bit-arrays/bit-arrays-tests.factor b/basis/bit-arrays/bit-arrays-tests.factor index c10eba4750..b8ec3f7811 100644 --- a/basis/bit-arrays/bit-arrays-tests.factor +++ b/basis/bit-arrays/bit-arrays-tests.factor @@ -78,7 +78,7 @@ sequences.private tools.test ; t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t } bit-array>integer ] unit-test -{ 49 } [ 49 dup set-bits [ ] count-by ] unit-test +{ 49 } [ 49 dup set-bits [ ] count ] unit-test { 1 } [ ?{ f t f t } byte-length ] unit-test diff --git a/basis/bloom-filters/bloom-filters-tests.factor b/basis/bloom-filters/bloom-filters-tests.factor index decefe17fa..205c5e116a 100644 --- a/basis/bloom-filters/bloom-filters-tests.factor +++ b/basis/bloom-filters/bloom-filters-tests.factor @@ -70,7 +70,7 @@ IN: bloom-filters.tests { t } [ 1000 [ drop most-positive-fixnum random 1000 + ] map full-bloom-filter [ bloom-filter-member? ] curry map - [ ] count-by + [ ] count ! TODO: This should be 10, but the false positive rate is currently very ! high. 300 is large enough not to prevent builds from succeeding. 300 <= diff --git a/basis/compiler/cfg/branch-splitting/branch-splitting.factor b/basis/compiler/cfg/branch-splitting/branch-splitting.factor index f6047e9925..3ed216117c 100644 --- a/basis/compiler/cfg/branch-splitting/branch-splitting.factor +++ b/basis/compiler/cfg/branch-splitting/branch-splitting.factor @@ -49,7 +49,7 @@ IN: compiler.cfg.branch-splitting UNION: irrelevant ##peek ##replace ##inc ; -: split-instructions? ( insns -- ? ) [ irrelevant? not ] count-by 5 <= ; +: split-instructions? ( insns -- ? ) [ irrelevant? not ] count 5 <= ; : short-tail-block? ( bb -- ? ) { [ successors>> empty? ] [ instructions>> length 2 = ] } 1&& ; diff --git a/basis/compiler/cfg/builder/alien/boxing/boxing.factor b/basis/compiler/cfg/builder/alien/boxing/boxing.factor index 228e2759e9..6620308454 100644 --- a/basis/compiler/cfg/builder/alien/boxing/boxing.factor +++ b/basis/compiler/cfg/builder/alien/boxing/boxing.factor @@ -13,7 +13,7 @@ SYMBOL: struct-return-area SYMBOLS: int-reg-reps float-reg-reps ; : reg-reps ( reps -- int-reps float-reps ) - [ second ] reject [ [ first int-rep? ] count-by ] [ length over - ] bi ; + [ second ] reject [ [ first int-rep? ] count ] [ length over - ] bi ; : record-reg-reps ( reps -- reps ) dup reg-reps [ int-reg-reps +@ ] [ float-reg-reps +@ ] bi* ; diff --git a/basis/compiler/tree/escape-analysis/recursive/recursive.factor b/basis/compiler/tree/escape-analysis/recursive/recursive.factor index 3f8746dd41..8cba6954ad 100644 --- a/basis/compiler/tree/escape-analysis/recursive/recursive.factor +++ b/basis/compiler/tree/escape-analysis/recursive/recursive.factor @@ -11,7 +11,7 @@ IN: compiler.tree.escape-analysis.recursive : congruent? ( alloc1 alloc2 -- ? ) { { [ 2dup [ boolean? ] either? ] [ eq? ] } - { [ 2dup 2length @ = not ] [ 2drop f ] } + { [ 2dup 2length = not ] [ 2drop f ] } [ [ [ allocation ] bi@ congruent? ] 2all? ] } cond ; diff --git a/basis/cpu/x86/64/unix/unix.factor b/basis/cpu/x86/64/unix/unix.factor index 5ab78d1d71..1cbe41b4fd 100644 --- a/basis/cpu/x86/64/unix/unix.factor +++ b/basis/cpu/x86/64/unix/unix.factor @@ -55,5 +55,5 @@ M: x86.64 dummy-int-params? f ; M: x86.64 dummy-fp-params? f ; M: x86.64 %prepare-var-args - [ second reg-class-of float-regs? ] count-by 8 min + [ second reg-class-of float-regs? ] count 8 min [ EAX EAX XOR ] [ AL swap MOV ] if-zero ; diff --git a/basis/fixups/fixups.factor b/basis/fixups/fixups.factor index 1f46c3e20b..1b74e8aea5 100644 --- a/basis/fixups/fixups.factor +++ b/basis/fixups/fixups.factor @@ -60,6 +60,7 @@ CONSTANT: word-renames { { "natural-sort!" { "sort!" "0.99" } } { "natural-bubble-sort!" { "bubble-sort!" "0.99" } } { "random-integers" { "randoms" "0.99" } } + { "count*" { "percent-of" "0.99" } } { "more?" { "deref?" "0.99" } } } diff --git a/basis/formatting/formatting.factor b/basis/formatting/formatting.factor index d02c39f197..7c7498f0af 100644 --- a/basis/formatting/formatting.factor +++ b/basis/formatting/formatting.factor @@ -149,7 +149,7 @@ text = (formats|plain-text)* ]=] : printf-quot ( format-string -- format-quot n ) - parse-printf [ [ callable? ] count-by ] keep [ + parse-printf [ [ callable? ] count ] keep [ dup string? [ 1quotation ] [ [ 1 - ] dip ] if over [ ndip ] 2curry ] map nip [ compose-all ] [ length ] bi ; inline diff --git a/basis/io/sockets/secure/openssl/openssl.factor b/basis/io/sockets/secure/openssl/openssl.factor index ef79eb78db..94b0521f23 100644 --- a/basis/io/sockets/secure/openssl/openssl.factor +++ b/basis/io/sockets/secure/openssl/openssl.factor @@ -440,7 +440,7 @@ M: ssl-handle dispose* "*." ?head [ { [ tail? ] - [ [ [ CHAR: . = ] count-by ] bi@ - 1 <= ] + [ [ [ CHAR: . = ] count ] bi@ - 1 <= ] } 2&& ] [ = diff --git a/basis/math/vectors/vectors.factor b/basis/math/vectors/vectors.factor index 4490475521..12213627f7 100644 --- a/basis/math/vectors/vectors.factor +++ b/basis/math/vectors/vectors.factor @@ -171,7 +171,7 @@ GENERIC: vall? ( v -- ? ) M: object vall? [ ] all? ; inline GENERIC: vcount ( v -- count ) -M: object vcount [ ] count-by ; inline +M: object vcount [ ] count ; inline GENERIC: vany? ( v -- ? ) M: object vany? [ ] any? ; inline diff --git a/core/sequences/sequences-docs.factor b/core/sequences/sequences-docs.factor index feabe8c215..de5950322b 100644 --- a/core/sequences/sequences-docs.factor +++ b/core/sequences/sequences-docs.factor @@ -1415,30 +1415,16 @@ HELP: map-sum } ; HELP: count -{ $values { "seq" sequence } { "n" integer } } -{ $description "Efficiently returns the number of elements that are true." } -{ $notes "This word used to take a quotation; that word is now " { $link count-by } "." } -{ $examples - { $example - "USING: sequences prettyprint ;" - "{ 1 2 f f f } count ." - "2" - } -} ; - -HELP: count-by { $values { "seq" sequence } { "quot" quotation } { "n" integer } } { $description "Efficiently returns the number of elements that the predicate quotation matches." } { $examples { $example "USING: math ranges sequences prettyprint ;" - "100 [1..b] [ even? ] count-by ." + "100 [1..b] [ even? ] count ." "50" } } ; -{ count count-by } related-words - HELP: selector { $values { "quot" { $quotation ( ... elt -- ... ? ) } } @@ -2031,7 +2017,6 @@ ARTICLE: "sequences-combinators" "Sequence combinators" "Counting:" { $subsections count - count-by } "Superlatives with " { $link min } " and " { $link max } ":" { $subsections diff --git a/core/sequences/sequences-tests.factor b/core/sequences/sequences-tests.factor index 2c44ca94d3..8e7b203dfd 100644 --- a/core/sequences/sequences-tests.factor +++ b/core/sequences/sequences-tests.factor @@ -302,10 +302,10 @@ unit-test { 328350 } [ 100 [ sq ] map-sum ] unit-test -{ 5 } [ { 1 f 3 f 5 f 7 f 9 f } count ] unit-test +{ 5 } [ { 1 f 3 f 5 f 7 f 9 f } [ ] count ] unit-test -{ 50 } [ 100 [ even? ] count-by ] unit-test -{ 50 } [ 100 [ odd? ] count-by ] unit-test +{ 50 } [ 100 [ even? ] count ] unit-test +{ 50 } [ 100 [ odd? ] count ] unit-test { { "b" "d" } } [ { 1 3 } { "a" "b" "c" "d" } nths ] unit-test { { "a" "b" "c" "d" } } [ { 0 1 2 3 } { "a" "b" "c" "d" } nths ] unit-test diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index 5822fcc5c2..ce5d307dcb 100644 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -1181,12 +1181,9 @@ M: repetition sum [ elt>> ] [ length>> ] bi * ; inline : map-sum ( ... seq quot: ( ... elt -- ... n ) -- ... n ) [ 0 ] 2dip [ dip + ] with-assoc each ; inline -: count-by ( ... seq quot: ( ... elt -- ... ? ) -- ... n ) +: count ( ... seq quot: ( ... elt -- ... ? ) -- ... n ) [ 1 0 ? ] compose map-sum ; inline -: count ( ... seq -- ... n ) - [ ] count-by ; inline - : cartesian-each ( ... seq1 seq2 quot: ( ... elt1 elt2 -- ... ) -- ... ) [ with each ] 2curry each ; inline diff --git a/extra/sequences/extras/extras-docs.factor b/extra/sequences/extras/extras-docs.factor index 6f8a5e3c9e..f21115b99d 100644 --- a/extra/sequences/extras/extras-docs.factor +++ b/extra/sequences/extras/extras-docs.factor @@ -69,13 +69,13 @@ HELP: 2map-index { $description "Calls the quotation with each pair of elements of the two sequences and their index on the stack, with the index on the top of the stack. Collects the outputs of the quotation and outputs them into a new sequence of the same type as the first sequence." } { $see-also 2map map-index } ; -HELP: count-by* +HELP: percent-of { $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "%" rational } } { $description "Outputs the fraction of elements in the sequence for which the predicate quotation matches." } -{ $examples { $example "USING: math ranges prettyprint sequences.extras ;" "100 [1..b] [ even? ] count-by* ." "1/2" } } ; +{ $examples { $example "USING: math ranges prettyprint sequences.extras ;" "100 [1..b] [ even? ] percent-of ." "1/2" } } ; HELP: collapse { $values diff --git a/extra/sequences/extras/extras-tests.factor b/extra/sequences/extras/extras-tests.factor index 72cc579398..86eaf1a80e 100644 --- a/extra/sequences/extras/extras-tests.factor +++ b/extra/sequences/extras/extras-tests.factor @@ -282,7 +282,7 @@ strings tools.test ; { 1 } [ { 1 f 3 2 } ?infimum ] unit-test { 1 } [ { 1 3 2 } ?infimum ] unit-test -{ 3/10 } [ 10 [ 3 < ] count-by* ] unit-test +{ 3/10 } [ 10 [ 3 < ] percent-of ] unit-test { { 0 } } [ "ABABA" "ABA" start-all ] unit-test { { 0 2 } } [ "ABABA" "ABA" start-all* ] unit-test @@ -308,7 +308,7 @@ strings tools.test ; H{ { t 6 } { f 5 } } { 0 0 1 1 2 3 4 2 3 4 5 } } [ - { 2 7 1 8 1 7 1 8 2 8 4 } [ even? ] occurrence-count-by + { 2 7 1 8 1 7 1 8 2 8 4 } [ even? ] occurrence-count ] unit-test { @@ -322,7 +322,7 @@ strings tools.test ; H{ { 8 3 } { 1 3 } { 2 2 } { 4 1 } { 7 2 } } { 0 0 0 0 1 1 2 1 1 2 0 } } [ - { 2 7 1 8 1 7 1 8 2 8 4 } [ ] occurrence-count-by + { 2 7 1 8 1 7 1 8 2 8 4 } [ ] occurrence-count ] unit-test { diff --git a/extra/sequences/extras/extras.factor b/extra/sequences/extras/extras.factor index a04dced8f4..e128db43e7 100644 --- a/extra/sequences/extras/extras.factor +++ b/extra/sequences/extras/extras.factor @@ -295,12 +295,9 @@ PRIVATE> : 0accumulate ( ... seq quot: ( ... prev elt -- ... next ) -- ... final newseq ) over 0accumulate-as ; inline -: occurrence-count-by ( seq quot: ( elt -- elt' ) -- hash seq' ) +: occurrence-count ( seq quot: ( elt -- elt' ) -- hash seq' ) '[ nip @ over inc-at* drop ] [ H{ } clone ] 2dip 0accumulate ; inline -: occurrence-count ( seq -- hash seq' ) - [ ] occurrence-count-by ; inline - : nth-index ( n obj seq -- i ) [ = dup [ drop 1 - dup 0 < ] when ] with find drop nip ; @@ -842,8 +839,10 @@ PRIVATE> : replicate-into ( ... seq quot: ( ... -- ... newelt ) -- ... ) over [ length ] 2dip '[ _ dip _ set-nth-unsafe ] each-integer ; inline -: count-by* ( ... seq quot: ( ... elt -- ... ? ) -- ... % ) - over [ count-by ] [ length ] bi* / ; inline +: percent-of ( ... seq quot: ( ... elt -- ... ? ) -- ... % ) + over length 0 = + [ 2drop 0 ] + [ over [ count ] [ length ] bi* / ] if ; inline : sequence-index-operator-last ( n seq quot -- n quot' ) [ [ nth-unsafe ] curry [ keep ] curry ] dip compose ; inline