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.

34.5 Bracketing Operator Declarations<br />

A bracketing operator declaration has the special reserved word opr where a functional declaration would have an<br />

identifier. <strong>The</strong> value parameter list, rather than being surrounded by parentheses, is surrounded by the brackets being<br />

defined. A bracketing operator declaration may have any number of parameters, keyword parameters, and varargs<br />

parameters in the value parameter list. Static parameters may also be present, between the special reserved word opr<br />

and the parameter list. Any paired Unicode brackets may be so defined except ordinary parentheses and white square<br />

brackets.<br />

An expression consisting of zero or more comma-separated expressions surrounded by a bracket pair will invoke a<br />

bracketing operator declaration. <strong>The</strong> compiler considers all bracketing operator declarations for that type of bracket<br />

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

rules for overloaded functionals. For example, the expression 〈p, q〉 might invoke the following bracketing method<br />

declaration:<br />

(∗ angle bracket notation for inner product ∗)<br />

opr 〈x :Vector, y : Vector〉 = ∑ [i ← x.indices]x i · y i<br />

(∗ vector space norm (may not be the most efficient) ∗)<br />

opr ‖x :Vector‖ = sqrt〈x, x〉<br />

34.6 Subscripting Operator Method Declarations<br />

A subscripting operator method declaration has the special reserved word opr where a method declaration would<br />

have an identifier. <strong>The</strong> value parameter list, rather than being surrounded by parentheses, is surrounded by a pair of<br />

brackets. A subscripting operator method declaration may have any number of value parameters, keyword parameters,<br />

and varargs parameters in that value parameter list. Static parameters may also be present, between the special reserved<br />

word opr and the parameter list. Any paired Unicode brackets may be so defined except ordinary parentheses and<br />

white square brackets; in particular, the square brackets ordinarily used for indexing may be used.<br />

An expression consisting of a subexpression immediately followed (with no intervening whitespace) by zero or more<br />

comma-separated expressions surrounded by brackets will invoke a subscripting operator method declaration. Methods<br />

for the expression preceding the bracketed expression list are considered. <strong>The</strong> compiler considers all subscripting operator<br />

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

according to the usual overloading rules. For example, the expression foo p might invoke the following subscripting<br />

method declaration because expressions in the square brackets are rendered as subscripts:<br />

(∗ subscripting method ∗)<br />

opr [x :BizarroIndex] = self.bizarroFetch(x)<br />

34.7 Subscripted Assignment Operator Method Declarations<br />

A subscripted assignment operator method declaration has the special reserved word opr where a method declaration<br />

would have an identifier. <strong>The</strong> value parameter list, rather than being surrounded by parentheses, is surrounded by a<br />

pair of brackets; this is then followed by the operator := and then a second value parameter list in parentheses, which<br />

must contain exactly one non-keyword value parameter. A subscripted assignment operator method declaration may<br />

have any number of value parameters within the brackets; these value parameters may include keyword parameters and<br />

varargs parameters. A result type may appear after the second value parameter list, but it must be (). Static parameters<br />

may also be present, between the special reserved word opr and the first parameter list. Any paired Unicode brackets<br />

234

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

Saved successfully!

Ooh no, something went wrong!