[plt-scheme] style question

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Sun Sep 20 20:59:00 EDT 2009

Thanks for the answers. I decided to throw all the stateful stuff into
a struct and pass that around. (I don't know why I hadn't thought of
that before, actually.) Everything manages to stay functional and
avoid mutation, plus the structures I pass around contain a model of
the evolution of the computation if I need that for debugging.

Sorry, Matthias, but I didn't have time to write it three times. It's
a port of about 1000 lines of Python code and I don't have time to do
all three versions, even if Scheme code is somewhat less verbose.
Maybe if it were 1000 lines of Java...

Todd

On Sat, Sep 19, 2009 at 2:54 PM, Anthony Cowley <acowley at seas.upenn.edu> wrote:
> 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.