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.

evaluates to “miles are larger” . A more interesting example is described in Section 6.5.<br />

13.22 Typecase Expressions<br />

Syntax:<br />

Flow ::= typecase TypecaseBindings in (TypecaseTypeRefs ⇒ Expr + ) + [Else] end<br />

TypecaseBindings ::= Id<br />

| Binding<br />

| ( BindingList )<br />

Binding ::= Id = Expr<br />

BindingList ::= Binding (, Binding) ∗<br />

TypecaseTypeRefs ::= TypeRef<br />

| ( TypeRefList )<br />

A typecase expression begins with the special reserved word typecase followed by a sequence of bindings (either<br />

an identifier or a sequence of an identifier followed by the token = , followed by an expression), followed by the<br />

special reserved word in , a sequence of typecase clauses (each consisting of a sequence of guarding types followed<br />

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

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

A typecase expression evaluates its bindings and checks each typecase clause to determine which typecase clause<br />

matches. A single identifier x (where x is a valid local identifier) as the binding of a typecase expression is a<br />

shorthand for x = x . Each subexpression in the bindings is evaluated and its value is bound to the corresponding<br />

identifier. To find a matched typecase clause, the guarding types of each typecase clause are compared to the types of<br />

the identifiers bound in the bindings in order. <strong>The</strong> right-hand side of the first matched clause (and only that clause) is<br />

evaluated. If no matched clause is found, a MatchFailure exception is thrown. <strong>The</strong> right-hand side of each clause<br />

forms a block expression and has the various properties of block expressions (described in Section 13.11). <strong>The</strong> optional<br />

else clause always matches. <strong>The</strong> value of a typecase expression is the value of the right-hand side of the matched<br />

clause. <strong>The</strong> type of a typecase expression is the union type of the types of all right-hand sides of the typecase<br />

clauses.<br />

For example:<br />

typecase x = myLoser.myField in<br />

String ⇒ x.append(“foo”)<br />

Number ⇒ x + 3<br />

Object ⇒ yogiBerraAutograph<br />

end<br />

Note that “x ” has a different type in each clause.<br />

13.23 Atomic Expressions<br />

Syntax:<br />

Flow ::= atomic Expr<br />

| tryatomic Expr<br />

As <strong>Fortress</strong> is a parallel language, an executing <strong>Fortress</strong> program consists of a set of threads (See Section 4.4 for a<br />

discussion of parallelism in <strong>Fortress</strong>). In multithreaded programs, it is often convenient for a thread to evaluate some<br />

expressions atomically. For this purpose, <strong>Fortress</strong> provides atomic expressions.<br />

106

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

Saved successfully!

Ooh no, something went wrong!