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.

(−b + sqrt(b 2 − 4ac))/2a<br />

n n e (−n) sqrt(2πn)<br />

a k b n−k<br />

x 1 y 2 − x 2 y 1<br />

1/2gt 2<br />

n(n + 1)/2<br />

(j + k)!/(j!k!)<br />

1/3 3/5 5/7 7/9 9/11<br />

17.3 meter/second<br />

17.3 m/s<br />

u · (v × w)<br />

(A ∪ B)INTERSECT C<br />

(A ∪ B) ∩ C<br />

i < j ≤ k ∧ p ≺ q<br />

print(“<strong>The</strong> answers are ” (p + q) “ and ” (p − q))<br />

〈2, 3, 4, 5〉<br />

13.9 Object Expressions<br />

Syntax:<br />

Val ::= object [Extends] (FldDef | MdDef ) ∗ end<br />

Object expressions denote object values; they do not require evaluation. Syntactically, they start with the special<br />

reserved word object , followed by an optional extends clause, field declarations, method declarations, and finally<br />

the special reserved word end . <strong>The</strong> type of an object expression is an anonymous object trait type that extends<br />

the traits listed in the extends clause of the object expression. <strong>The</strong> object trait type does not include the methods<br />

introduced by the object expression (i.e., those methods not provided by any supertraits of the object expression).<br />

Every evaluation of an object expression has the same anonymous object trait type. Each object trait type is associated<br />

with a program location; any two object expressions with the same extends clause have different object trait types.<br />

Unlike object declarations (described in Chapter 10), object expressions are not allowed to include modifiers nor value<br />

parameters nor static parameters nor where clauses (described in Chapter 11). While object declarations must not<br />

include any free static variable (i.e., all static variables in an object declaration must occur either as a static parameter<br />

or as a where -clause variable), object expressions may include free static variables.<br />

For example, the following object expression:<br />

fT(x :T) = object f : T = x end<br />

has a static variable T that is not its static parameter nor its where -clause variable.<br />

<strong>The</strong> following example expression evaluates to a new object extending trait List:<br />

object extends { List }<br />

first() = throw Error<br />

rest() = throw Error<br />

cons(x) = Cons(x,self)<br />

append(xs) = xs<br />

end<br />

96

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

Saved successfully!

Ooh no, something went wrong!