[plt-scheme] style question

From: Anthony Cowley (acowley at seas.upenn.edu)
Date: Sat Sep 19 14:54:31 EDT 2009

On Sat, Sep 19, 2009 at 10:52 AM, Todd O'Bryan <toddobryan at gmail.com> wrote:
> As a result, I have to keep track of the number of parts I've replaced
> and increment the count each time I replace a new substring. If I were
> doing this as an OO program, I'd create a Converter class and have the
> number of parts so far be a field. Doing the same thing functionally,
> it seems like I have two choices--either have the counter be a
> module-level variable that all the functions have access to, or pass
> it around as a parameter to every function that needs it or calls
> other functions that need it.

I was doing something similar recently and used some of my
unsafePerformIO-is-welcome! monad helpers. Here's something that does
what I think you're doing,
<http://paste.lisp.org/display/87325>

This style has the nice property of passing the counter state through
all the parsing functions without having it as an explicit formal
parameter.

The required code is just some macro support over a simple state
monad. I can send you the library code if it would be helpful.

Anthony


Posted on the users mailing list.