[plt-scheme] style question

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Mon Sep 21 12:02:04 EDT 2009

Oh, I agree completely. It's just that this one wasn't small enough
for me to do that with. Trust me, I've been writing and rewriting lots
of parts of Scheme code as I try to get more comfortable with the
language.

Todd

On Mon, Sep 21, 2009 at 10:10 AM, Matthias Felleisen
<matthias at ccs.neu.edu> wrote:
>
> 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.