Errors acummulate

Three readers (so far) have called my attention to errors in “The Semicolon Wars,” my latest American Scientist column.

First, I referred to the programming languages ML, Haskell and Miranda as “pure” functional languages. ML doesn’t belong in that group. Although it is a language that has deep roots in the functional-programming community, ML allows assignment statements that produce side effects, violating any reasonable standard of functional “purity.”

Second, one of the example Lua programs given in the illustration on page 302 is hopelessly confused. As published, the program reads:

function factI (n)
  local accumulator = 1
  for i = 1,n do
    accum = accumulator*i
  end
  return accum
end

The definition should be:

function factI (n)
  local accumulator = 1
  for i = 1,n do
    accumulator = accumulator*i
  end
  return accumulator
end

The story of this goof may be worth telling, at least briefly. I would never trust myself to write even the smallest program correctly without testing the code. In this case I did confirm that the program compiled successfully and gave sensible-looking results, and then I did a copy-and-paste to get the text into the illustration. So what went wrong? In the tested version of the program I named the local variable “accum.” Later, I worried that this abbreviated form might be a bit cryptic to some readers, and so I decided to spell the word out in full. Surely I could make such a trivial change without retesting…?

Mea culpa. And thanks to David Hemmendinger, Steve Christensen and Kirsten Chevalier for their alert reading.

This entry was posted in computing.

Comments are closed.