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.

‘}’. If such a clause contains only one trait, the enclosing braces may be elided. A trait reference is either a declared<br />

trait identifier or an abbreviated type for aggregate expressions (discussed in Section 13.28).<br />

Every trait extends the trait Object. A trait with an extends clause extends every trait listed in its extends clause.<br />

If a trait T extends trait U , we call T a subtrait of U and U a supertrait of T . Extension is transitive; if T extends<br />

U it also extends all supertraits of U . Extension is also reflexive: T extends itself. <strong>The</strong> extension relation induced<br />

by a program is the smallest relation satisfying these conditions. This relation must form an acyclic hierarchy rooted<br />

at trait Object.<br />

We say that trait T strictly extends trait U if and only if (i) T extends U and (ii) T is not U . We say that trait T<br />

immediately extends trait U if and only if (i) T strictly extends U and (ii) there is no trait V such that T strictly<br />

extends V and V strictly extends U . We call U an immediate supertrait of T and T an immediate subtrait of U .<br />

A trait with an excludes clause excludes every trait listed in its excludes clause. If a trait T excludes a trait U ,<br />

the two traits are mutually exclusive. No third trait can extend them both and neither can extend the other. A trait U<br />

can optionally have an excludes clause.<br />

If a trait declaration of T includes a comprises clause, the trait must not be extended with immediate subtraits other<br />

than those that listed in its comprises clause. If a trait T has an empty comprises clause, no other traits can<br />

extend T .<br />

For example, the following trait declaration:<br />

trait Catalyst extends Object<br />

self.catalyze(reaction: Reaction):()<br />

end<br />

declares a trait Catalyst with no modifiers, no static parameters, no excludes clauses, no comprises clauses, and<br />

no where clauses. Trait Catalyst extends a trait named Object. A single method (named catalyze ) is declared,<br />

which has a parameter of type Reaction and the return type (). <strong>The</strong> special name self is explicitly declared as a<br />

parameter. See Section 9.2 for details about when self is implicitly declared, and to which entity it refers.<br />

<strong>The</strong> following example trait:<br />

trait Molecule comprises { OrganicMolecule, InorganicMolecule }<br />

mass():Mass<br />

end<br />

comprises of two traits: OrganicMolecule and InorganicMolecule. <strong>The</strong>refore, the following trait declaration is not<br />

allowed:<br />

(∗ Not allowed! ∗)<br />

trait ExclusiveMolecule extends Molecule end<br />

Traits OrganicMolecule and InorganicMolecule may be exclusive:<br />

trait OrganicMolecule extends Molecule excludes InorganicMolecule end<br />

trait InorganicMolecule extends Molecule end<br />

OrganicMolecule and InorganicMolecule exclude each other, even though only OrganicMolecule has an excludes<br />

clause. For example, the following trait declaration is not allowed:<br />

(∗ Not allowed! ∗)<br />

trait InclusiveMolecule extends { InorganicMolecule, OrganicMolecule } end<br />

A trait is allowed to have multiple immediate supertraits. <strong>The</strong> following trait has two immediate supertraits:<br />

trait Enzyme extends { OrganicMolecule, Catalyst } end<br />

71

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

Saved successfully!

Ooh no, something went wrong!