19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

40.2 Constructing Linear Sequences<br />

40.2.1 makeLinearSequenceT extends Object,nat n(item: T):LinearSequenceT, n<br />

A new linear sequence of length n is returned. Every element of the linear sequence is initialized to be the same as<br />

the given item .<br />

40.2.2 computeLinearSequenceT extends Object,nat n(f:IndexInt → T): LinearSequenceT, n<br />

A new linear sequence of length n is returned. Element j of the new linear sequence is initialized to a value computed<br />

by calling the given function f with argument j .<br />

40.3 <strong>The</strong> Trait <strong>Fortress</strong>.Core.HeapSequence<br />

A value of type HeapSequenceT is an array-like object that contains items of type T . <strong>The</strong> length of a heap<br />

sequence is in general not known statically, but can be discovered by asking for its length. A variable of type<br />

HeapSequenceT occupies the amount of storage required to hold a reference; this reference refers to an object<br />

that occupies an amount of storage greater than or equal to the amount that would be occupied by a variable of type<br />

LinearSequenceT, n where n is the length of the heap sequence.<br />

Heap sequences, like linear sequences and unlike arrays, are not too fancy. <strong>The</strong> main things you can do with heap<br />

sequences are subscripting and subscripted assignment. Concatenation is not supported, because a basic principle of<br />

the low-level types is that none of the operations, other than explicit construction of a heap sequence, does any heap<br />

allocation. However, a range of static size may be used to index a heap sequence; the result is a linear sequence.<br />

trait HeapSequenceT extends Object extends Object comprises {}<br />

opr [j: IndexInt]:T throws { IndexOutOfBoundsException }<br />

opr nat m[r: RangeOfStaticSizeIndexInt, m]:LinearSequenceT, m<br />

throws { IndexOutOfBoundsException }<br />

opr [j :IndexInt] := (v: T):() throws { IndexOutOfBoundsException }<br />

opr nat m[r: RangeOfStaticSizeIndexInt, m] := (v: LinearSequenceT, m):()<br />

throws { IndexOutOfBoundsException }<br />

reverse(selfStart: IndexInt,length: IndexInt):() throws { IndexOutOfBoundsException }<br />

opr |self| : IndexInt<br />

end<br />

40.3.1 opr [j: IndexInt]:T throws { IndexOutOfBoundsException }<br />

Subscripting returns element j of this heap sequence. Indexing is zero-origin; an IndexOutOfBoundsException is<br />

thrown unless 0 ≤ j < n , where n is the length of the heap sequence.<br />

276

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!