[plt-scheme] How do I do this in true functional style?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Dec 1 09:12:15 EST 2004


1. how about a look at this


It's a four-line recursive function for reading in csv from a line  
file. Is this really a problem?

2. The choice of data is the key problem in all programming. It often  
requires experimental programming to find just the right one. The  
recursion in the data definition determines the recursion in the  
function 90% of the time. If it repeats, abstract. That's the lesson of  
HtDP. And it applies to C, Java, and Scheme.

3. Have you considered that all this graphics stuff really comes from  
matrix mathematics and that these people have done it for over a  
century w/o a single set! ? So it must work.

-- Matthias

On Dec 1, 2004, at 1:07 AM, Devlin Bentley wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> I was mentally going over how I was going to write a mini wireframe[1]
> 3d-renderer in Scheme, and right afterwards I went and skimmed through
> parts of HTDP.  After finishing some reading in HTDP (and noticing
> that set! is not introduced until Chapter 34), I began to feel sick to
> my stomach with my current plan for doing my renderer.
> The way I was going to do it up until about 10 minutes ago involved
> taking a text file with comma separated integers and using each three
> sequential integers as indices in a 3-dimensional array of booleans
> when setting the read in index to true.
> The actual drawing algorithm would then traverse the array (also an
> icky hack that should not be done, nexted for loops in Scheme just
> because they are easy for my brain to think of....) and use a "next in
> line" function to jump between valid points.
> Now it'd all work, and take me an hour or two tops to code, but the  
> thing is:
> - Lots of set-vector! statements being executed, tons of them.
> - Hacked on nested iterative loops (I've already programmed this in
> before, it looks horrible and feels "obviously wrong", not a recursive
> algorithm at all!)
> - I seriously get the feeling that my solution is best suited for a
> more procedural language.  (Not surprising considering I originally
> wrote it out in procedural psuedocode)
> How am I approaching this wrong?  My instructor doesn't really care
> how it gets done (The final "fun" assignment of the quarter is to draw
> something, anything, in 3D) and no matter how I do end up doing it, it
> will be fun having a little mini 3d room rendered on my screen, but I
> will feel a lot better about it if I can have a true recursive (and if
> possible functional!) solution.
> Is this even possible given that I need to read in data from a text  
> file?
> Aside from converting the text file into one gigantic list and parsing
> through it, is there any way for me to get around using a million and
> one sets, or are situations like this considered times when it is
> "acceptable" to use mutators?
> No comments on my stupid choice of a data structure!  I know it is
> stupid, but the sheer ease of coding a wireframe algorithm for points
> in an array has lured me in!
> [1] A lot easier than I at first suspected.
> -- 
> --------
> Devlin Bentley
> Com2Kid at gmail.com

Posted on the users mailing list.