[plt-scheme] Processing lists

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Wed Mar 11 17:08:39 EDT 2009

> On Mar 5, 2009, at 9:30 PM, aditya shukla wrote:
>> Earlier i was thinking of having  a counter which i would increment
>> whenever an occurrence is found  .Any suggestions on how to think in more of
>> a functional paradigm.

I'm not sure if this will help, but here's the feeling I get when I'm
doing imperative vs. functional programming:

In imperative programming, I feel like I'm manipulating things. The
computer is something like the cockpit of a plane. I know that when I
move switches or change controls, something somewhere changes as a
result of what I'm doing. My job is to figure out how to twiddle all
the knobs and move the controls in the right way so that I end up
where I want to go.

In functional programming, I feel like I'm solving a puzzle. I have a
bunch of generic pieces that I can use for any puzzle, but I also have
pieces that are provided by the problem. I can combine pieces together
to make new pieces. If a particular piece is unusually complicated, I
can wrap other pieces around it so that it fits with the other pieces.
By the time I finish, I have a coherent picture that includes the
pieces I was given, but they're now a part of what I wanted.

This is all very abstract, but I think it's helpful. Stop asking
yourself, "What should I make the computer do?" and ask yourself, "How
can I make an expression that represents what I want out of the pieces
that I have?"

Hope that helps,
Todd


Posted on the users mailing list.