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.

treeSum(t : TreeLeaf) = 0<br />

treeSum(t : TreeNode) = do<br />

var accum := 0<br />

do<br />

accum += treeSum(t.left)<br />

also do<br />

accum += treeSum(t.right)<br />

also do<br />

accum += t.datum<br />

end<br />

accum<br />

end<br />

13.13 Label and Exit<br />

Syntax:<br />

Flow ::= label Id Expr + end Id<br />

| exit [Id] [with Expr]<br />

Block expressions may be labeled with an identifier. Syntactically, a label expression begins with the special reserved<br />

word label followed by an identifier, inner expressions (label block), the special reserved word end , and<br />

finally the same identifier. A label expression evaluates its inner expressions in order and any inner exit expression<br />

can exit the label block. Syntactically, an exit expression begins with the special reserved word exit followed<br />

by an optional identifier of the targeted label block with an optional value (exit value), which consists of the special<br />

reserved word with followed by an expression. If an exit expression does not have a with clause, it has an implicit<br />

exit value () . If an exit expression does not exist within a label expression, the value of the label expression<br />

is the value of the last expression of the label block. If an exit expression exists, the expression completes abruptly<br />

and attempts to transfer control to the end of the targeted label block. <strong>The</strong> targeted label block evaluates to the exit<br />

value of the exit expression. <strong>The</strong> type of a label expression is a union of the type of the last expression of its label<br />

block and the types of any exit values. <strong>The</strong> type of an exit expression is BottomType.<br />

If one or more try expressions are nested between an exit expression and the targeted label block, the finally<br />

clauses of these expressions are run in order, from innermost to outermost. Only when every intervening finally<br />

clause has completed normally does the targeted block complete normally. If any finally clause completes abruptly<br />

by throwing an exception, the exit expression fails to exit, the label expression completes abruptly, and the<br />

exception is propagated.<br />

Here is a simple example:<br />

label I 95<br />

if goingTo(Sun)<br />

then exit I 95 with x32B<br />

else x32A<br />

end<br />

end I 95<br />

<strong>The</strong> expression exit I 95 with x32B completes abruptly and attempts to transfer control to the end of the targeted<br />

label block label I 95 . <strong>The</strong> targeted label block completes normally with value x32B .<br />

99

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

Saved successfully!

Ooh no, something went wrong!