]> gitweb.factorcode.org Git - factor.git/commitdiff
factor: rename count-by back to count. count* -> percent-of
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 5 Feb 2023 19:12:09 +0000 (13:12 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 26 Feb 2023 23:11:03 +0000 (17:11 -0600)
count is way more useful as a combinator than as [ ] count-by.

16 files changed:
basis/bit-arrays/bit-arrays-tests.factor
basis/bloom-filters/bloom-filters-tests.factor
basis/compiler/cfg/branch-splitting/branch-splitting.factor
basis/compiler/cfg/builder/alien/boxing/boxing.factor
basis/compiler/tree/escape-analysis/recursive/recursive.factor
basis/cpu/x86/64/unix/unix.factor
basis/fixups/fixups.factor
basis/formatting/formatting.factor
basis/io/sockets/secure/openssl/openssl.factor
basis/math/vectors/vectors.factor
core/sequences/sequences-docs.factor
core/sequences/sequences-tests.factor
core/sequences/sequences.factor
extra/sequences/extras/extras-docs.factor
extra/sequences/extras/extras-tests.factor
extra/sequences/extras/extras.factor

index c10eba47504c2536b6bb59cef7a91b7abf8fc771..b8ec3f7811317a91e57d757e93d6e4b66ae613f4 100644 (file)
@@ -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 <bit-array> dup set-bits [ ] count-by ] unit-test
+{ 49 } [ 49 <bit-array> dup set-bits [ ] count ] unit-test
 
 { 1 } [ ?{ f t f t } byte-length ] unit-test
 
index decefe17fa037660784be69a8d2638e1916a3aaa..205c5e116a3cdd00d57a54cc6f47142132ba28f3 100644 (file)
@@ -70,7 +70,7 @@ IN: bloom-filters.tests
 { t } [ 1000 <iota> [ 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 <=
index f6047e99256a179ae9751a69d19059104faf7462..3ed216117c82a96ed2112b1da0659ff1f7fcf9ee 100644 (file)
@@ -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&& ;
index 228e2759e9b7fa6b2f6579855d52eb2511d79544..6620308454d813841857c360cab3026af63db01b 100644 (file)
@@ -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* ;
index 3f8746dd4119e827c1d87d5e81de4453ea01f836..8cba6954ad1f1b1bc7ed51bcbcf2cabf16462a8a 100644 (file)
@@ -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 ;
 
index 5ab78d1d71233aac8b255aae9af230999d3abaf2..1cbe41b4fd8abf0aa059741fe9fb5ce9fabee865 100644 (file)
@@ -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 ] [ <byte> AL swap MOV ] if-zero ;
index 1f46c3e20bf7f4163e0f8bf29ce7b692d4144cf2..1b74e8aea58200b2c1e6afe900ee8e1b4cf81f7e 100644 (file)
@@ -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" } }
 }
 
index d02c39f197366d3546beef42c992ec6f26be630a..7c7498f0af249df49499eaecdeec35cf227cb056 100644 (file)
@@ -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
index ef79eb78dba43d62b489e39ea6c93535103bd8f3..94b0521f2396ea366246b6261e8fbd643ad96cc3 100644 (file)
@@ -440,7 +440,7 @@ M: ssl-handle dispose*
     "*." ?head [
         {
             [ tail? ]
-            [ [ [ CHAR: . = ] count-by ] bi@ - 1 <= ]
+            [ [ [ CHAR: . = ] count ] bi@ - 1 <= ]
         } 2&&
     ] [
         =
index 44904755217e2712b5c8b066a6d010bca80591bb..12213627f7f716a533604308d35f609e08320b41 100644 (file)
@@ -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
index feabe8c215b15c9901c16789378881be9131f5d4..de5950322b40fc1f4a3c73297451fb8d09965eda 100644 (file)
@@ -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
index 2c44ca94d3dc3c3d5af9863b6651ae00f96c1f16..8e7b203dfd44aa9077328e205f6f27a27d391103 100644 (file)
@@ -302,10 +302,10 @@ unit-test
 
 { 328350 } [ 100 <iota> [ 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 <iota> [ even? ] count-by ] unit-test
-{ 50 } [ 100 <iota> [ odd?  ] count-by ] unit-test
+{ 50 } [ 100 <iota> [ even? ] count ] unit-test
+{ 50 } [ 100 <iota> [ 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
index 5822fcc5c2c4aec48c5cc70814a3f8576d151b8c..ce5d307dcba7aece04bfe436de8ed08b06bf759f 100644 (file)
@@ -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
 
index 6f8a5e3c9e73869b03b2253db5f1db36cbbda7e3..f21115b99dd562ae66855b9ef54b8808f2173f7b 100644 (file)
@@ -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
index 72cc57939801e5c48d0a79fb8e809689d594a9a0..86eaf1a80e40fe2b6750182060fffea5bc9c7136 100644 (file)
@@ -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 <iota> [ 3 < ] count-by* ] unit-test
+{ 3/10 } [ 10 <iota> [ 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
 
 {
index a04dced8f48869d2b79ab4882b931584bd5c0632..e128db43e7c5e9b1da4c0aad0739cbdcdb10d823 100644 (file)
@@ -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