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.

to the value of the condition expression. <strong>The</strong> two values are compared according to an optional operator specified.<br />

If the operator is omitted, it defaults to = or ∈. If the condition expression has type Generator or if the guarding<br />

expression does not, then the default operator is = ; otherwise, it is ∈. It is a static error if the specified operator is not<br />

defined for these types or if the operator’s return type is not Boolean.<br />

<strong>The</strong> right-hand side of the first matched clause (and only that clause) is evaluated. If no matched clause is found, a<br />

MatchFailure exception is thrown. <strong>The</strong> right-hand side of each clause forms a block expression and has the various<br />

properties of block expressions (described in Section 13.11). <strong>The</strong> optional else clause always matches. <strong>The</strong> value<br />

of a case expression is the value of the right-hand side of the matched clause. <strong>The</strong> type of a case expression is the<br />

union type of the types of all right-hand sides of the case clauses.<br />

For example, the following case expression specifies the operator ∈:<br />

case planet ∈of<br />

{ Mercury, Venus, Earth, Mars } ⇒ “inner”<br />

{ Jupiter, Saturn, Uranus, Neptune, Pluto } ⇒ “outer”<br />

else ⇒ “remote”<br />

end<br />

but the following does not:<br />

case 2 + 2 of<br />

4 ⇒ “it really is 4”<br />

5 : 7 ⇒ “we were wrong again”<br />

end<br />

13.21 Extremum Expressions<br />

Syntax:<br />

Flow ::= case (largest | smallest ) [Op] of (Expr ⇒ Expr + ) + end<br />

An extremum expression uses the same syntax as a case expression (described in Section 13.20) except that the<br />

special reserved word largest or smallest is used where a case expression would have a condition expression<br />

and an extremum expression does not have an optional else clause.<br />

All guarding expressions of an extremum expression is evaluated in parallel. See Section 4.4 for a discussion of<br />

parallel evaluation. To find the largest (or smallest) quantity, the values of the guarding expressions are compared in<br />

parallel according to an optional operator specified. If the operator is omitted, it defaults to CMP . <strong>The</strong> union of the<br />

types of all the candidate expressions must be a subtype of TotalOrderOperatorsT, ,CMP for some T ,<br />

< , ≤ , ≥ , and > , if a default operator is used (see Section 37.2 for details about the TotalOrderOperators trait).<br />

If an explicit operator is used, the explicit operator replaces CMP in TotalOrderOperatorsT, ,CMP .<br />

<strong>The</strong> right-hand side of the clause with the largest (smallest) guarding expression (and only that clause) is evaluated.<br />

If more than one guarding expressions are tied for largest (smallest), the leftmost clause is evaluated. <strong>The</strong> righthand<br />

side of each clause forms a block expression and has the various properties of block expressions (described in<br />

Section 13.11). <strong>The</strong> value of an extremum expression is the value of the right-hand side of the matched clause. <strong>The</strong><br />

type of an extremum expression is the union type of the types of all right-hand sides of the clauses.<br />

For example, the following code:<br />

case largest of<br />

1 mile ⇒ “miles are larger”<br />

1 kilometer ⇒ “we were wrong again”<br />

end<br />

105

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

Saved successfully!

Ooh no, something went wrong!