[whatwg] Fake Code

And this particular example should be recursive.  Unfolding inherently
recursive procedures with an explicit stack, perhaps to construct an
enumerator or to simulate a coroutine, is a technical detail that does not
belong here.
Chris

-----Original Message-----
From: whatwg-bounces@lists.whatwg.org
[mailto:whatwg-bounces at lists.whatwg.org] On Behalf Of Garrett Smith
Sent: Wednesday, July 30, 2008 8:46 AM
To: WHATWG List
Subject: [whatwg] Fake Code

Examples should work.

Citation from:
http://www.whatwg.org/specs/web-apps/current-work/#outlines

------------------------------------------------------------------------
The following JavaScript function shows how the tree walk could be
implemented. The root argument is the root of the tree to walk, and
the enter and exit arguments are callbacks that are called with the
nodes as they are entered and exited. [ECMA262]

function (root, enter, exit) {
  var node = root;
  start: do while (node) {
    enter(node);
    if (node.firstChild) {
      node = node.firstChild;
      continue start;
    }
    while (node) {
      exit(node);
      if (node.nextSibling) {
        node = node.nextSibling;
        continue start;
      }
      if (node == root)
        node = null;
      else
        node = node.parentNode;
    }
  }
}
------------------------------------------------------------------------

This code cannot be interpreted in a compliant implementation of
EcmaScript. It has more syntax errors than I can count. It is unclear
what the author thinks this code will do. If its intent were clearer,
and the syntax errors fewer, it might be possible for me to help out
by fixing them. The above code is not even close to ECMA262.

Examples should not contain errors.

Garrett

Received on Wednesday, 30 July 2008 00:27:10 UTC