count is way more useful as a combinator than as [ ] count-by.
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
{ 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 <=
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&& ;
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* ;
: congruent? ( alloc1 alloc2 -- ? )
{
{ [ 2dup [ boolean? ] either? ] [ eq? ] }
- { [ 2dup 2length @ = not ] [ 2drop f ] }
+ { [ 2dup 2length = not ] [ 2drop f ] }
[ [ [ allocation ] bi@ congruent? ] 2all? ]
} cond ;
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 ;
{ "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" } }
}
]=]
: 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
"*." ?head [
{
[ tail? ]
- [ [ [ CHAR: . = ] count-by ] bi@ - 1 <= ]
+ [ [ [ CHAR: . = ] count ] bi@ - 1 <= ]
} 2&&
] [
=
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
} ;
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 -- ... ? ) } }
"Counting:"
{ $subsections
count
- count-by
}
"Superlatives with " { $link min } " and " { $link max } ":"
{ $subsections
{ 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
: 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
{ $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
{ 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
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
{
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
{
: 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 ;
: 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