Function: (count-up xs) : Returns a list of lists of the form (x n), where x is an element of xs and n is the number of times x occurs in xs. This list is sorted to present most frequent items first (otherwise it would be sorted pseudorandomly).
Useful for, well, counting things up; I've used this to count word and letter frequencies, calculate the totient function, create a couple of histograms, compute the number of distinct permutations of a list, help print out a number's prime factorization, test the randomness of supposedly random functions, and do some other things.
(def count-up (xs)
(let u (table)
(each x xs
(++ (u x 0)))
(sort (compare > cadr) (tablist u))))
Ah, that's a fun one. Could use counts to get a table in vanilla Arc, except that it hard-codes recursion on cdrs, so it won't work for strings. From arc.arc:
(def counts (seq (o c (table)))
(if (no seq)
c
(do (++ (c (car seq) 0))
(counts (cdr seq) c))))
It's also easy to not notice the built-in sortable from srv.arc:
(def sortable (ht (o f >))
(let res nil
(maptable (fn kv
(insort (compare f cadr) kv res))
ht)
res))