[plt-scheme] style question

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sat Sep 19 11:12:14 EDT 2009

I recommend you write it all three ways in Scheme. You do have  
classes. Then compare.


On Sep 19, 2009, at 10:52 AM, Todd O'Bryan wrote:

> I'm writing a text converter that goes through a text file and
> replaces parts of it with place-holders that I can fill back in later.
>
> 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.
>
> So, here's my question--which is better style in Scheme? If I don't
> provide the variable, it's not really *global* in the scary sense that
> global variables are bad, but suppose two different processes both use
> the same module at the same time. Does each get its own copy of the
> variable, or is there really only one copy that the two processes
> would share (and possibly confuse each other as a result)? Passing
> around the counter seems cleaner conceptually--all the dependencies
> are explicit--but it just feels clunky.
>
> Thanks,
> Todd
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.