<foreach> clarifications requested

Dear VBWG,

The description of <foreach> in the Candidate Recommendation of VoiceXML
2.1 is underspecified in a number of respects.  The following are areas
in which we request clarification to ensure greater consistency of
implementation.

[1] Misleading section title

Section 6 is titled "Concatenating Prompts Dynamically Using <foreach>".
Whilst the use of <foreach> for prompt generation is clearly one
important use case, the ability to use <foreach> as executable content
(with or without prompt content) provides more general programmatic use.

Suggestion: a general title such as "Iteration with <foreach>" (or
similar) to capture the broader utility of this new element.


[2] Type of "array"

The table in Section 6 states that "array" is "An ECMAScript expression
that must evaluate to an array; otherwise, an error.semantic event is
thrown."

There are several ways to achieve array-like behaviour in ECMAScript and
thus clarity in the spec will avoid some likely interop issues.  Perhaps
the intent is that the object must evaluate to an "Array" instance or
merely that the object be able to dereference array[0], array[1] etc.

Suggestion: The specification should explicitly state the precise
ECMAScript implementation (e.g. "Array") and ideally provide a canonical
means of determining whether an object is an Array object.  Note that
typeof for an Array is "object" and thus it is necessary to look at the
constructor or prototype verify Array-ness.


[3] Unspecified "store" behavior

The table in Section 6 states that "item" is "The variable that stores
each array item upon each iteration of the loop."   The specification is
mute on whether "store" is an "assignment by reference" where possible
rather than "assignment by copy".

It should be noted that VoiceXML 2.0 is likewise mute on the same issue
for <var> and <assign>.

However, the Implementation Report includes an example that requires
"assignment by reference" in order to execute in the way implied by the
test vector.

Suggestion: assignment by reference is fine but this behavior should be
explicitly specified rather than implicit through an example in the IR.


[4] Under-specified iteration behavior

The examples imply that array is assumed to have values set for indices
of "0", "1", "2" and so on.  The specification is mute on other
legitimate ECMAScript array content.  Are the following arrays semantic
errors or acceptable but with undefined behavior?

Note from ECMA-262:

     15.4 Array Objects
     Array objects give special treatment to a certain class of property
     names.  A property name P (in the form of a string value) is an
     _array index_ if and only if ToString(ToUint32(P)) is equal to P
and
     ToUint32(P) is not equal to 2^{32}-1.  (88)

ECMAScript provides for:

- Sparse arrays: e.g. array with indices 0,1,2,10  (note that length is
11 for this example, not 4)
- Non-zero index start: e.g. array with indices 3,4,5
- Array with no content

ECMAScript provides array-like behaviour for:

- Negative indices: e.g. array with indices -2,-1,0,1,2
- Non-integer indices: e.g. array with indices 0,1,2,3,"string",3.14
- Object indices: e.g. array with indices 0,1,2,3,ObjectX

Suggestion: document what we believe to be the intended spirit of the
specification.

1. <foreach> iterates over content values for "array" starting with
entry integer "0" and incrementing until an undefined entry is found.
2. If the array does not content an entry with index "0" no content will
be executed and no error is raised
3. All values that are not sequential integers starting from "0" will be
ignored without error

Note that because length is the max-index+1, iterating for (i=0;
i<length; i++) will encounter undefined values in sparse arrays.


Regards,
  Andrew

---
Andrew Hunt
VP Engineering, Holly Connects
Level 11, 301 George Street, Sydney, NSW 2000, Australia
Ph: +61 2 8207 8207   Mob: +61 411 486 870
Email: andrew.hunt@holly-connects.com

Received on Friday, 18 August 2006 16:10:55 UTC