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.

end<br />

Enzyme inherits the abstract method mass from OrganicMolecule, declares the abstract method reactionSpeed ,<br />

and declares the concrete method catalyze which is inherited as an abstract method from its supertrait Catalyst.<br />

9.3 Abstract Field Declarations<br />

Syntax:<br />

AbsFldDecl ::= AbsFldMod ∗ Id IsType<br />

AbsFldMod ::= hidden | settable | wrapped | UniversalMod<br />

UniversalMod ::= private | test<br />

Traits may also include abstract field declarations that are implicit declarations of abstract getter methods. Syntactically,<br />

an abstract field declaration consists of an optional sequence of modifiers followed by the field name, followed<br />

by the token : , and the type of the field.<br />

By default, a field declaration implicitly declares a getter method for the field unless there is an explicit getter declared<br />

in the enclosing trait. An implicit getter method takes no arguments, has the same name as the field, and has a return<br />

type equal to the field type. When called, the implicit getter returns the value of the field when called.<br />

Abstract field declarations can include the following special modifiers:<br />

hidden :<br />

A field declaration with the modifier hidden has no implicit getter method.<br />

settable : A field declaration with the modifier settable has an implicit setter method unless there is an explicit<br />

setter declared in the enclosing trait. An implicit setter method takes a parameter (with no default expression) whose<br />

type is the type of the field, and returns () . When called, the implicit setter rebinds the corresponding field to its<br />

argument. If a field declaration includes the modifier settable and hidden , only an abstract setter is declared. If a<br />

field declaration includes the modifier hidden without settable , it is a static error.<br />

wrapped : If a field declaration of f has the modifier wrapped and the type of f is trait type T , and T is not a naked<br />

type variable, then the enclosing trait S implicitly includes “forwarding methods” for all methods in T that are also<br />

inherited from any supertrait of S. Each of these methods simply calls the corresponding method on the trait referred to<br />

by field f. If the trait declaration enclosing f explicitly declares a method m that conflicts with an implicitly declared<br />

forwarding method m ′ , then the enclosing trait contains only method m, not m ′ . If the trait declaration enclosing f<br />

inherits a concrete method m that conflicts with an implicitly declared forwarding method m ′ , then the enclosing trait<br />

contains only method m, not m ′ . Because wrapped fields do not change declarations of methods but change definitions<br />

of methods, they only affect implementations; APIs do not include wrapped fields.<br />

For example, in the following declarations:<br />

trait DictionaryT<br />

put(T):()<br />

get():T<br />

end<br />

trait WrappedDictionaryT extends DictionaryT<br />

wrapped val: DictionaryT<br />

get():T<br />

end<br />

74

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

Saved successfully!

Ooh no, something went wrong!