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.

IOException ⇒throw ForbiddenException(e)<br />

end<br />

<strong>The</strong> following example ensures that file is closed properly even if an IO error occurs:<br />

try<br />

open(file)<br />

inp = read(file)<br />

write(inp,newFile)<br />

catch e<br />

IOException ⇒throw ForbiddenException(e)<br />

finally<br />

close(file)<br />

end<br />

13.27 Static Expressions<br />

Static expressions denote static values. Given instantiations of all static parameters (described in Chapter 11) in<br />

scope of a static expression, the value of the static expression can be determined statically. Static expressions can be<br />

used as instantiations of static parameters. We define the set of static expressions by first defining the types of static<br />

expressions, and distinguishing static values from the closely related literal values. We then describe the expressions<br />

that evaluate to the various kinds of static values.<br />

13.27.1 Types of Static Expressions<br />

<strong>The</strong>re are three groups of traits that describe literals and static expressions:<br />

1. <strong>The</strong> literal traits, which describe boolean, character, string, and numerals. For example, the literal true has trait<br />

BooleanLiteraltrue and a character literal has trait Character. See Section 13.1 for a discussion of <strong>Fortress</strong><br />

literals.<br />

2. <strong>The</strong> constant traits, which describe values denoted by expressions composed from literals and operators; the type<br />

of a constant expression encodes the value of the expression. For example, the type of a constant expression<br />

3 + 5 , IntegerConstantfalse, 3 + 5 , encodes the value of the expression.<br />

3. <strong>The</strong> static traits, which describe values denoted by expressions composed from literals, operators, and bool ,<br />

nat , and int parameters; here the type does not encode the value of the expression, but the value of the<br />

expression can nevertheless be known statically if specific values are specified for the static parameters. Also,<br />

in situations where the type of an expression composed solely from literals and operators nevertheless cannot<br />

be described by a constant trait, then a static trait may be used to describe it instead. For example, a static<br />

expression 2(3 + m) where m is a nat parameter has trait NaturalStatic.<br />

<strong>The</strong> only operation on literals that produces a new literal (as opposed to a constant) is concatenation by using the operator<br />

‖ . One may concatenate mixed string and character literals, producing a string literal. For example, “foo” ‖ ”bar”<br />

yields “foobar”. One may also concatenate two natural numerals of the same radix, producing a new natural numeral<br />

of that radix. For example, deadc 16 ‖0de 16 yields deadc0de 16 .<br />

Every literal trait extends an appropriate constant trait, and every constant trait extends an appropriate static trait. So<br />

every literal is also a constant expression, and every constant expression is a static expression.<br />

110

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

Saved successfully!

Ooh no, something went wrong!