Ticket #69 (closed enhancement: wontfix)

Opened 2 years ago

Last modified 1 year ago

Bounds on Array length and Array indexing

Reported by: lth Assigned to: lth
Type: enhancement Priority: major
Milestone: M2 Component: Proposals
Version: 4 Keywords:
Cc: brendan, jeffdyer, graydon, cormac, dherman

Description (last modified by lth) (diff)

Rationale:

  • Bounded arrays are good for error detection.

Primary proposal:

Arrays shall have a read-write property bound of type uint. The initial value of this property shall be 232-1.

The bound property holds the maximum value of the length property: Any operation that would increase length beyond bound shall fail with a !RangeError exception being thrown.

If bound is given a value less than length then a RangeError? is thrown.

Any attempt to access a numbered property on the array object beyond the value of bound shall fail with a !RangeError exception being thrown.

Attachments

Change History

Changed 2 years ago by brendan

  • description changed from Rationale: Bounded arrays are good for error detection. Primary proposal: Arrays shall have a read-write property `bound` of type uint. The initial value of this property shall be 2^32-1. The `bound` property holds the maximum value of the `length` property: Any operation that would increase `length` beyond `bound` shall fail with a `!RangeError` exception being thrown. If `bound` is given a value less than `length` then `length` is set to the new value of `bound`. Any attempt to access a numbered property on the array object beyond the value of `bound` shall fail with a `!RangeError` exception being thrown. to Rationale: Bounded arrays are good for error detection. Primary proposal: Arrays shall have a read-write property `bound` of type uint. The initial value of this property shall be 2^32^-1. The `bound` property holds the maximum value of the `length` property: Any operation that would increase `length` beyond `bound` shall fail with a `!RangeError` exception being thrown. If `bound` is given a value less than `length` then `length` is set to the new value of `bound`. Any attempt to access a numbered property on the array object beyond the value of `bound` shall fail with a `!RangeError` exception being thrown.

Changed 2 years ago by brendan

  • cc set to brendan, jeffdyer, graydon, cormac, dherman

Syntax, we want syntax!

type Pair.<T> = [T, T](2);

or

type Pair.<T> = [T, T, ()];  // works today modulo lack of TyLams

or

type Pair.<T> = [T, T];

where the last case is not what the RI does today, and today's meaning would be written thus:

type TwoOrMore.<T> = [T, T, T...];

or some equivalent Kleene star notation for element types.

/be

Changed 2 years ago by brendan

See #68, which with the first syntax proposal above might be combined with this proposal:

let intPair = new [int, int](2);

and likewise for the second and third proposals.

/be

Changed 2 years ago by lth

  • description changed from Rationale: Bounded arrays are good for error detection. Primary proposal: Arrays shall have a read-write property `bound` of type uint. The initial value of this property shall be 2^32^-1. The `bound` property holds the maximum value of the `length` property: Any operation that would increase `length` beyond `bound` shall fail with a `!RangeError` exception being thrown. If `bound` is given a value less than `length` then `length` is set to the new value of `bound`. Any attempt to access a numbered property on the array object beyond the value of `bound` shall fail with a `!RangeError` exception being thrown. to Rationale: Bounded arrays are good for error detection. Primary proposal: Arrays shall have a read-write property `bound` of type uint. The initial value of this property shall be 2^32^-1. The `bound` property holds the maximum value of the `length` property: Any operation that would increase `length` beyond `bound` shall fail with a `!RangeError` exception being thrown. If `bound` is given a value less than `length` then a RangeError is thrown. Any attempt to access a numbered property on the array object beyond the value of `bound` shall fail with a `!RangeError` exception being thrown.

Changed 2 years ago by lth

  • owner set to lth
  • priority changed from minor to major
  • summary changed from Support for bounded arrays to Bounds on Array length and Array indexing
  • description changed from Rationale: Bounded arrays are good for error detection. Primary proposal: Arrays shall have a read-write property `bound` of type uint. The initial value of this property shall be 2^32^-1. The `bound` property holds the maximum value of the `length` property: Any operation that would increase `length` beyond `bound` shall fail with a `!RangeError` exception being thrown. If `bound` is given a value less than `length` then a RangeError is thrown. Any attempt to access a numbered property on the array object beyond the value of `bound` shall fail with a `!RangeError` exception being thrown. to Rationale: * Bounded arrays are good for error detection. Primary proposal: Arrays shall have a read-write property `bound` of type uint. The initial value of this property shall be 2^32^-1. The `bound` property holds the maximum value of the `length` property: Any operation that would increase `length` beyond `bound` shall fail with a `!RangeError` exception being thrown. If `bound` is given a value less than `length` then a RangeError is thrown. Any attempt to access a numbered property on the array object beyond the value of `bound` shall fail with a `!RangeError` exception being thrown.
  • milestone changed from M1 to M2

Can of worms:

We have a minimum length implied by the type syntax [int,String,*], it's not possible to take this below length=2 (or the type system is subverted). But this lower bound is not visible to the program except as an error when trying to set length<2, and it's not an error to access the array beyond the minimum (or add that).

We want to be able to set an upper bound for safe programming, and it implies no access below the bound.

The tuples syntax proposal (#120), if accepted, sort of implies both lower and upper bounds on the length, but says nothing (yet) about accessing below that upper bound.

Allen suggested a "fixedLength" property to cover both, and that's possible.

Conclusion: lth takes this back to the wiki for a real proposal, along with #120, looking to resolutions for #68 and #66.

Changed 1 year ago by lth

  • status changed from new to closed
  • resolution set to wontfix

Replaced by the array/tuple proposal and the vector proposal.

Note: See TracTickets for help on using tickets.