+2  A: 

When I do this, knowing that I'm only ever going to have a list and not a matrix, I use:

count =: 4 : '+/x=y'

Or for multiple searches in the list:

count =: 4 : '+/x=y'"0 1

Your method copies over only the elements that are equal to x, then counts the result. Summing the ones for equality is one less operation.

MPelletier
As always from you, an insightful answer. Thanks again!
Gregory Higley
Not a problem, I'm just glad I could help.
MPelletier
+2  A: 

I agree with the algorithm provided by MPelletier. Since you're asking for concision, tacit phrasings may be worth looking at. Here's one such program, assigned to a name:

count =: +/ @: =

It can also be used as an anonymous verb, as in this example:

   4 (+/ @: =) 3 4 4 3 4 7 9
3

A synonym is [: +/ =

As MPelletier said, this algorithm works when what you want to count are atoms in a simple list. (A similar need that would require a different approach would be counting matrices matched in a list of similarly-shaped matrices.)

kaleidic
Yeah, once MPelletier had provided my with the algorithm, I did turn it into its tacit form. (I used the `@:` variant rather than the capped one.) I created a verb called `counts` which in its dyadic form is basically `+/ @: = "0 1` and in its monadic form returns a two-column matrix which counts the given list.
Gregory Higley
Gregory Higley
I think a monadic verb that tallies for the nub should be kept minimalistic: `[: +/"1 =` seems the "classic" calculation of this. If you want to do sorting, or joining to the nub, fine, but I recommend you don't mix those into the "main" verb.
kaleidic
Thanks @kaleidic, I usually go for the simplest, direct form and forget to make it tacit. My understanding of the `@`, `@.`, and `@:` adverbs is seriously lacking.
MPelletier