ES4 draft: Vector

Waldemar Horwat waldemar at
Mon Mar 10 17:27:38 PDT 2008

> new Vector.<T> ( length=..., fixed=... )

It would be helpful for readability to have the types here.

> The |Vector| constructor is implementation-defined.

This is misleading.  Usually when a standard states that something is implementation-defined, it means that its semantics are not specified in the standard.  Having no standard-defined vector constructor would be strange indeed.

If you merely don't want to write pseudo-code for the Vector constructor, please just omit the "Implementation" section.

> Vector( object )

> When the |Vector| class object is called as a function, it creates a new 
> variable-length |Vector| object of type |*| ...
> static meta function invoke(object) {
>     if (object is Vector.<*>)
>         return object;

The description and code don't match.

[Also, I'm a bit unclear about how parametrized types currently work.  The overview document has examples that seem to indicate that you call bound types as functions.  What happens when you call Vector.<Foo> as a function and pass it a Vector.<Bar>?]

toLocaleString:  This seems overspecified.  Do you want to explicitly define what happens if the vector is modified in the middle of running this?


Vector<X> cannot be a subtype of Vector<Y> even if X is a subtype of Y.  If it were, the type system would be unsound:  you could pass a Vector<X> to a function F expecting a Vectory<Y> and then have F write a Y into that vector.

every, filter, etc.:  These seem overspecified.  For example, the definition of filter states that the implementation must perform the lookup and fetch of each found element twice, which unnecessarily forbids more efficient implementations.

forEach:  Why is clamp here?

"The static indexOf method ...":  indexOf isn't a static method.

Why does indexOf return AnyNumber?

lastIndexOf:  What happens when you do i-- on a uint with the value of 0?  Do you get 4294967295?

sort:  Doesn't return anything.

>     if (items.length < delcnt) {
>         let shift = delcnt - items.length;
>         for ( let n=0, i=first; n < shift ; n++, i++ )
>             this[i] = this[i+shift];
>         length -= shift;
>     }
>     else {
>         let shift = items.length - delcnt;
>         for ( let n=shift-1, i=first+shift; n >= 0 ; n--, i-- )
>             this[i] = this[i-shift];
>     }

Both of these seem wrong.  I think there are at least four different errors here.


Need to raise length first.

>     for ( let i=0 ; i < numitems ; i++ )
>         this[newlimit-i] = this[oldlimit-i];

The bounds on this loop are wrong.

1.4:  Typo:  "defined on directly on"

When you iterate through Maps, you get the old length if the Map is modified during the iteration.  When you iterate through Vectors, you get the new length.  The discrepancy seems jarring.

fixed should be a constant property or be removed altogether.  It's useless as a variable -- anybody can change the length of the vector at any time anyway, and now code that hands out references to vectors to clients has to deal with bozos who make those vectors fixed just for grins.

What happens if you try to index a vector with +Infinity or NaN?  I assume it's RangeError, but don't know enough about how numerically named properties work.

> prototype function every(this:Vector.<*>, checker, thisObj=undefined)
>     (this.intrinsic::every(checker, thisObj is Object) ? thisObj : null);
> prototype function filter(this:Vector.<*>, checker, thisObj=undefined)
>     (this.intrinsic::filter(checker, thisObj is Object) ? thisObj : null);
> prototype function forEach(this:Vector.<*>, eacher, thisObj=undefined)
>     (this.intrinsic::forEach(checker, thisObj is Object) ? thisObj : null);

Why are you passing a boolean as the thisObj argument to intrinsic::every et al.?


More information about the Es4-discuss mailing list