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.

It is also possible to convert a measurement in one unit to a measurement of another unit of the same dimension, as in<br />

the following example:<br />

kineticEnergy(3.14 kg, 32 f/s in m/s)<br />

<strong>The</strong> second argument to kineticEnergy is a measurement in feet per second, converted to meters per second.<br />

2.11 Aggregate Expressions<br />

As with mathematical notation, <strong>Fortress</strong> includes special syntactic support for writing down many common kinds of<br />

collections, such as tuples, arrays, matrices, vectors, maps, sets, and lists simply by enumerating all of the collection’s<br />

elements. We refer to an expression formed by enumerating the elements of a collection as an aggregate expression.<br />

<strong>The</strong> elements of an aggregate expression are computed in parallel.<br />

For example, we can define an array a in <strong>Fortress</strong> by explicitly writing down its elements, enclosed in brackets and<br />

separated by whitespaces, as follows:<br />

a = [0 1 2 3 4]<br />

Two-dimensional arrays can be written down by separating rows by newlines (or by semicolons). For example, we<br />

can bind b to a two-dimensional array as follows:<br />

b = [3 4<br />

5 6]<br />

<strong>The</strong>re is also support for writing down arrays of dimension three and higher. We bind c to a three-dimensional array<br />

as follows:<br />

c = [1 2<br />

3 4; ; 5 6<br />

7 8; ; 9 10<br />

11 12]<br />

Various slices of the array along the third dimension are separated by pairs of semicolons. (Higher dimensional arrays<br />

are also supported. When writing a four-dimensional array, slices along the fourth dimension are separating by triples<br />

of semicolons, and so on.)<br />

Vectors are written down just like one-dimensional arrays. Similarly, matrices are written down just like two-dimensional<br />

arrays. Whether an array aggregate expression reduces to an array, a vector, or a matrix is inferred from context (e.g.,<br />

the static type of a variable that such an expression is bound to). Of course, all elements of vectors and matrices must<br />

be numbers.<br />

A set can be written down by enclosing its elements in braces and separating its elements by commas. Here we bind<br />

s to the set of integers 0 through 4 :<br />

s = {0, 1, 2, 3, 4}<br />

<strong>The</strong> elements of a list are enclosed in angle brackets (written in ASCII as ):<br />

l = 〈0, 1, 2, 3, 4〉<br />

<strong>The</strong> elements of a map are enclosed in curly braces, with key/value pairs joined by the arrow ↦→ (written in ASCII as<br />

|->):<br />

27

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

Saved successfully!

Ooh no, something went wrong!