[plt-scheme] style question

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Sep 21 10:10:49 EDT 2009

Programmers who study new languages benefit from writing small sample  
programs that compare styles.

Even in Python there's more than one way to write a program, despite  
the GvR BS.

-- Matthias

On Sep 20, 2009, at 8:59 PM, Todd O'Bryan wrote:

> 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
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.