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.

may be so defined except ordinary parentheses and white square brackets; in particular, the square brackets ordinarily<br />

used for indexing may be used.<br />

An assignment expression consisting of an expression immediately followed (with no intervening whitespace) by zero<br />

or more comma-separated expressions surrounded by brackets, followed by the assignment operator :=, followed by<br />

another expression, will invoke a subscripted assignment operator method declaration. Methods for the expression<br />

preceding the bracketed expression list are considered. <strong>The</strong> compiler considers all subscript operator method declarations<br />

that are both accessible and applicable, and the most specific method declaration is chosen according to the usual<br />

overloading rules. When a compound assignment operator (described in Section 13.8) is used with a subscripting<br />

operator and a subscripted assignment operator, for example a 3 += k , both a subscripting operator declaration and<br />

a subscripted assignment operator declaration are required. For example, the assignment foo p := myWidget might<br />

invoke the following subscripted assignment method declaration:<br />

(∗ subscripted assignment method ∗)<br />

opr [x :BizarroIndex] := (newValue :Widget) = self.bizarroInstall(x,newValue)<br />

34.8 Conditional Operator Declarations<br />

A conditional operator is a binary operator (other than ‘:’) that is immediately followed by ‘:’; see Section 16.6.<br />

A conditional operator expression x@ :y is syntactic sugar for x@(fn () ⇒ y) ; that is, the right-hand operand is<br />

converted to a “thunk” (zero-parameter function) that then becomes the right-hand operand of the corresponding<br />

unconditional operator. <strong>The</strong>refore a conditional operator is simply implemented as an overloading of the operator that<br />

accepts a thunk.<br />

It is also permitted for a conditional operator to have a preceding as well as a following colon. A conditional operator<br />

expression x :@:y is syntactic sugar for (fn () ⇒ x)@(fn () ⇒ y) ; that is, each operand is converted to a thunk.<br />

This mechanism is used, for example, to define the results-comparison operator :∼:, which takes exceptions into<br />

account.<br />

<strong>The</strong> conditional ∧ and ∨ operators for boolean values, for example, are implemented as methods in this manner:<br />

opr ∧(self,other:Boolean) = if self then other else false end<br />

opr ∧(self,other:() → Boolean) = if self then other() else false end<br />

opr ∨(self,other:Boolean) = if self then true else other end<br />

opr ∨(self,other:() → Boolean) = if self then true else other() end<br />

34.9 Big Operator Declarations<br />

A big operator such as ∑ or ∏ is declared as a usual operator declaration. See Section 32.8.1 for an example<br />

declaration of a big operator. A big operator application is called a reduction expression and described in Section 13.18.<br />

235

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

Saved successfully!

Ooh no, something went wrong!