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.

<strong>The</strong> following restrictions apply: No two keyword-value pairs may have the same keyword. No keyword-value pair<br />

may precede a plain expression. No varargs expression may follow a keyword-value pair or precede a plain expression.<br />

<strong>The</strong>re must be at least one item. If there is exactly one item, it must be a varargs expression or a keyword-value pair<br />

(because an expression “(e) ” is simply a parenthesized expression, not a tuple.) Also, there can be at most one item<br />

with a varargs expression. In a varargs expression, the expression “e” must be of type OrderedGeneratorT for<br />

some T .<br />

<strong>The</strong> type of a tuple expression is a tuple type (as discussed in Section 8.4), which may be described by taking the<br />

tuple expression and replacing each element expression with its type, except that a varargs expression having type<br />

OrderedGeneratorT is replaced by T . . . (for the most specific T possible). <strong>The</strong> element expressions are all<br />

evaluated before the tuple is constructed, and if there is a varargs expression then the generator is used to construct a<br />

HeapSequence (described in Section 40.3) containing all the generated values; this HeapSequence then becomes an<br />

element of the tuple. Tuples are value objects. <strong>The</strong>re are no explicit deconstructors for tuples except multiple variable<br />

declarations as discussed in Section 6.3.<br />

13.28.1 Distinguishing a Keyword-Value Pair from an Equality Expression<br />

Because a keyword-value pair shares a syntax with an equality expression, we provide rules for disambiguation:<br />

• If an expression “identifier = e ” has no parentheses around it, then it is an equality expression unless it is part<br />

of a tuple expression with more than one element expression.<br />

• If the expression is in immediately surrounding parentheses with no other expression in the parentheses, then<br />

it is an equality expression unless the parenthesized expression is part of a juxtaposition sequence and is to be<br />

used as an argument to a function, in which case the parenthesized expression is a tuple expression.<br />

• Adding parentheses makes the expression an equality expression.<br />

• In the rare situations where “(identifier = e) ” is treated as an equality expression and it must be a tuple<br />

expression, “tuple(identifier = e) ” makes it a tuple expression where “tuple ” is an identity function defined<br />

in the <strong>Fortress</strong> standard libraries (as described in Section 13.32.4).<br />

13.29 Comprehensions<br />

Syntax:<br />

Comprehension ::= { Expr | GeneratorList }<br />

| { Expr ↦→ Expr | GeneratorList }<br />

| 〈 Expr | GeneratorList 〉<br />

| [ (ArrayComprehensionLeft | GeneratorList) + ]<br />

ArrayComprehensionLeft ::= Id ↦→ Expr<br />

| ( Id , IdList ) ↦→ Expr<br />

<strong>Fortress</strong> provides comprehension syntax for several aggregate expressions (described in Section 13.28). Generators<br />

(described in Section 13.17) produce values and bind the values to the identifiers that are used in the left-hand side of<br />

the token | (left-hand body). Most generators, unlike the sequential generator, may execute each evaluation of the<br />

left-hand body in a separate implicit thread. Comprehensions evaluate to aggregate values and have corresponding<br />

aggregate types.<br />

A set comprehension is enclosed in braces, with a left-hand body separated by the token | from a generator list. For<br />

example, the comprehension:<br />

{ x 2 | x ← {0, 1, 2, 3, 4, 5}, xMOD 2 = 0 }<br />

114

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

Saved successfully!

Ooh no, something went wrong!