archives

Computing History at Bell Labs

Over at Russ Cox's blog:

In 1997, on his retirement from Bell Labs, Doug McIlroy gave a fascinating talk about the “History of Computing at Bell Labs” ...

My favorite parts of the talk are the description of the bi-quinary decimal relay calculator and the description of a team that spent over a year tracking down a race condition bug in a missile detector (reliability was king: today you'd just stamp “cannot reproduce” and send the report back). But the whole thing contains many fantastic stories. It's well worth the read or listen. I also like his recollection of programming using cards: “It's the kind of thing you can be nostalgic about, but it wasn't actually fun.”

Can local variables assignments be considered pure functional without monads?

Okay, this might seem like an odd question, but is there contention on whether or not a while loop that performs assignment on local function variables is pure functional? For example the following Java code:

int process(int[] xs) 
{
  int zeros = 0;
  int sum = 0;
  int i=0;
  while (i < xs.Size) {
    if (xs[i] == 0)
      zeros++;
    sum += xs[i];
    ++i;
  }
  return sum - zeros;
}

Now I have heard frequently that the above code is considered to have side-effects because of the local assignments to variables. However, the mapping to pure-functional stack-based code (here shown in Cat) is very straightforward:

define process {
  // top argument = xs
  0 // zeros
  0 // sum
  0 // i
  [
    dig3 // bring xs to top of local stack
    dupd swap get_at eqz // xs[i] == 0
      [[inc] dip3] // inc zeros
      []
    if
    dupd swap get_at // tmp = xs[i]
    [bury3] dip // put xs to bottom of local stack
    swap [add_int] dip // sum += tmp
    inc // ++i
  ]
  [
    dig3 count [bury3] dip // tmp = xs.Size
    dupd lt_int // i < tmp
  ]
  while
  pop // remove i
  swap sub_int // sum-zeros
}

So, my problem is that I am not sure whether this is old news or new news. Any feedback would be appreciated.