TITLE: A Nice Example of a Functional Programming Pattern
AUTHOR: Eugene Wallingford
DATE: July 27, 2007 6:58 PM
DESC:
-----
BODY:
David Altenburg gives a nice example of a pattern you'll
find in functional programs, which he calls
Enumerate, Map, Filter, Accumulate.
This isn't the typical snappy pattern name, but it does
show deference to Chapter 2 of
Structure and Interpretation of Computer Programs,
which discusses in some detail this way of processing a
stream of data. I like this blog entry because it illustrates
nicely a difference between how functional programmers think
and how OO programmers think. He even gives idiomatic Java
and Ruby code to demonstrate the difference more clearly.
Seeing the Ruby example also makes clear just how powerful
first-order blocks can be in an OO language.
SICP
is a veritable catalog of the patterns of programs written
in a functional style. They aren't written in Alexander's
pattern style, but they are patterns nonetheless.
(In a snarkier mood, I might say:
I am sure some Lisp aficionado will explain that Enumerate,
Map, Filter, Accumulate isn't a pattern because we could
define a enumapfilacc macro and make it go away...)
-----