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.

esult<br />

end<br />

where result is a fresh variable. A reduction expression without a generator list:<br />

∑ g<br />

is equivalent to the following:<br />

∑ [x ← g]x<br />

Note that reduction expressions without generator lists can be used to conveniently sum any aggregate expression<br />

(described in Section 13.28), since every aggregate expression is a generator.<br />

13.19 If Expressions<br />

Syntax:<br />

Flow ::= if Expr then Expr + (elif Expr then Expr + ) ∗ [Else] end<br />

| (if Expr then Expr + (elif Expr then Expr + ) ∗ Else [end ])<br />

Else ::= else Expr +<br />

An if expression consists of the special reserved word if followed by a condition expression of type Boolean,<br />

followed by the special reserved word then , a sequence of expressions, an optional sequence of elif clauses (each<br />

consisting of the special reserved word elif followed by a condition expression, the special reserved word then ,<br />

and a sequence of expressions), an optional else clause (consisting of the special reserved word else followed by a<br />

sequence of expressions), and finally the special reserved word end . Each clause forms a block expression and has the<br />

various properties of block expressions (described in Section 13.11). An if expression first evaluates its condition<br />

expression. If the condition expression evaluates to true, the then clause is evaluated. Otherwise, the next to the<br />

then clause is evaluated. An elif clause evaluates its condition expression first and proceeds similarly to an if<br />

expression. <strong>The</strong> type of an if expression is the union of the types of all right-hand sides of the clauses. If there is no<br />

else clause in an if expression, then the last expression in every clause must evaluate to () . <strong>The</strong> special reserved<br />

word end may be elided if the if expression is immediately enclosed by parentheses. In such a case, an else clause<br />

is required.<br />

For example,<br />

if x ∈ {0, 1, 2} then 0<br />

elif x ∈ {3, 4, 5} then 3<br />

else 6 end<br />

13.20 Case Expressions<br />

Syntax:<br />

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

A case expression begins with the special reserved word case followed by a condition expression, followed by an<br />

optional operator, the special reserved word of , a sequence of case clauses (each consisting of a guarding expression<br />

followed by the token ⇒, followed by a sequence of expressions), an optional else clause (consisting of the special<br />

reserved word else followed by a sequence of expressions), and finally the special reserved word end .<br />

A case expression evaluates its condition expression and checks each case clause to determine which case clause<br />

matches. To find a matched case clause, the guarding expression of each case clause is evaluated in order and compared<br />

104

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

Saved successfully!

Ooh no, something went wrong!