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

From: Noel Welsh (noelwelsh at gmail.com)
Date: Mon Apr 20 01:58:42 EDT 2009

On Mon, Apr 20, 2009 at 3:42 AM, Matthias Felleisen
<matthias at ccs.neu.edu> wrote:
> No, we aren't purists. We are pragmatic. When an issue calls for mutation,
> we have no problem using it. When we can do without, we're better off. The
> key is to know when there's a call.

For this problem imperative = functional. The problem is basically a
fold over a list. If the seed/accumulator of the fold never leaks
outside the fold (i.e. it cannot be observed until the fold is
complete) you can mutate it all you want and still have a functional
implementation. This is related to the list monad, but I'm not
entirely precise on the details so I won't attempt an explanation.


Posted on the users mailing list.