03.08.2013 Views

PTOLEMY II - CiteSeerX

PTOLEMY II - CiteSeerX

PTOLEMY II - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.4 Composite Data Types<br />

3.4.1 Arrays<br />

Expressions<br />

Arrays are specified with curly brackets, e.g., “{1, 2, 3}” is an array of int, while “{"x",<br />

"y", "z"}” is an array of string. The types are denoted “{int}” and “{string}” respectively. An<br />

array is an ordered list of tokens of any type, with the only constraint being that the elements all have<br />

the same type. If an array is given with mixed types, the expression evaluator will attempt to losslessly<br />

convert the elements to a common type. Thus, for example,<br />

has value<br />

{1, 2.3}<br />

{1.0, 2.3}<br />

Its type is {double}. The elements of the array can be given by expressions, as in the example<br />

“{2*pi, 3*pi}.” Arrays can be nested; for example, “{{1, 2}, {3, 4, 5}}” is an array of<br />

arrays of integers. The elements of an array can be accessed as follows:<br />

>> {1.0, 2.3}(1)<br />

2.3<br />

which yields 2.3. Note that indexing begins at 0. Of course, if name is the name of a variable in scope<br />

102 Ptolemy <strong>II</strong>

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

Saved successfully!

Ooh no, something went wrong!