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.

Expressions<br />

from it. For instance,<br />

>> 1-[3, 0; 0, 3]<br />

[-2, 1; 1, -2]<br />

A matrix can be checked for equality with another matrix as follows:<br />

>> [3, 0; 0, 3]!=[3, 0; 0, 6]<br />

true<br />

>> [3, 0; 0, 3]==[3, 0; 0, 3]<br />

true<br />

For other comparisons of matrices, use the compare() function (see Table 5 on page 119). As with scalars,<br />

testing for equality using the == or != operators tests the values, independent of type. For example,<br />

>> [1, 2]==[1.0, 2.0]<br />

true<br />

To get type-specific equality tests, use the equals() method, as in the following examples:<br />

>> [1, 2].equals([1.0, 2.0])<br />

false<br />

>> [1.0, 2.0].equals([1.0, 2.0])<br />

true<br />

>><br />

3.4.3 Records<br />

A record token is a composite type containing named fields, where each field has a value. The<br />

value of each field can have a distinct type. Records are delimited by curly braces, with each field<br />

given a name. For example, “{a=1, b="foo"}” is a record with two fields, named “a” and “b”, with<br />

values 1 (an integer) and “foo” (a string), respectively. The value of a field can be an arbitrary expression,<br />

and records can be nested (a field of a record token may be a record token).<br />

Fields may be accessed using the period operator. For example,<br />

{a=1,b=2}.a<br />

yields 1. You can optionally write this as if it were a method call:<br />

{a=1,b=2}.a()<br />

The arithmetic operators +, −, *, /, and % can be applied to records. If the records do not have identical<br />

fields, then the operator is applied only to the fields that match, and the result contains only the fields<br />

Heterogeneous Concurrent Modeling and Design 105

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

Saved successfully!

Ooh no, something went wrong!