[plt-scheme] Re: help on how to write a frequency-counting function in a more functional way

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Apr 22 06:24:24 EDT 2009

On Apr 22, Kumar wrote:
> Just to tickle you guys, here is an elegant expression of PR's
> approach -
> sort ids.txt | uniq -c
> ... the really pragmatic solution ;-P

Inefficent, but close:

  (for/list ([x (in-list (remove-duplicates ids))])
    (list x (count (lambda (y) (equal? x y)) ids)))

and writing a `uniq' equivalent is easy -- but is it realy useful
enough to justify a library function?  (I've never seen `uniq -c' used
for anything else besides frequency counting -- and perhaps frquency
counting is common enough to add...)

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.