19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - 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.

Chapter 10<br />

Objects<br />

An object is a value object, a reference object, or a function object: It is a function object if it has an arrow type, a<br />

reference object if it has an object trait type that is not declared with the value modifier (see Section 10.3), and a<br />

value object otherwise (i.e., if it has a tuple type, the type (), or an object trait type declared with the value modifier).<br />

Value objects cannot have mutable fields, and they are completely determined by their type, environment and their<br />

fields: Value objects with the same type, environment and fields are indistinguishable. Thus, an implementation may<br />

freely copy value objects. Most objects with simple standard types, such as booleans, numeric literals, IEEE floatingpoint<br />

numbers, and integers are value objects. In contrast, reference objects are thought to “reside in memory”, and are<br />

identified by an object reference. A new object reference is created whenever a reference object is constructed, so that<br />

reference objects constructed separately are always distinct. Reference objects include arbitrary-precision numbers<br />

and aggregates such as arrays, lists and sets. Function objects are immutable and have no fields. Identity is not welldefined<br />

for function objects, and attempting to check whether two functions are equivalent returns an approximate<br />

result. Section 10.4 describes object equivalence in further detail.<br />

10.1 Object Declarations<br />

Syntax:<br />

ObjectDecl ::= ObjectHeader (MdDef | FldDef | PropertyDecl) ∗ end<br />

ObjectHeader ::= ObjectMod ∗ object Id [StaticParams] [([ObjectParams])] [Extends] FnClauses<br />

ObjectMod ::= TraitMod<br />

ObjectParams ::= ObjectParam(,ObjectParam) ∗<br />

| [ObjectParam(,ObjectParam) ∗ , ] ObjectVarargs<br />

| [ObjectParam(,ObjectParam) ∗ , ] [ObjectVarargs,] ObjectKeyword ( , ObjectKeyword) ∗<br />

ObjectVarargs ::= transient Id : TypeRef ...<br />

ObjectKeyword ::= ObjectParam=Expr<br />

ObjectParam ::= FldMod ∗ PlainParam<br />

| transient PlainParam<br />

FnClauses ::= [Throws] [Where] [Contract]<br />

Throws ::= throws MayTraitTypes<br />

Object declarations declare both object values and object trait types. Object declarations extend a set of traits from<br />

which they inherit methods. An object declaration inherits the concrete methods of its supertraits and must include<br />

a definition for every method declared but not defined by its supertraits. Especially, an object declaration must not<br />

include abstract methods (discussed in Section 22.3); it must define all abstract methods inherited from its<br />

supertraits. It is also allowed to define overloaded declarations of concrete methods inherited from its supertraits.<br />

77

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

Saved successfully!

Ooh no, something went wrong!