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.

An implicit range may be used only in certain contexts, such as array subscripts, that can supply implicit information.<br />

Suppose an implicit range is used as a subscript for an axis of array for which the lower bound is l and the upper bound<br />

is u.<br />

• <strong>The</strong> implicit range : is treated as l : u .<br />

• <strong>The</strong> implicit range : : c is treated as l : u :c.<br />

• <strong>The</strong> implicit range : b is treated as l : b .<br />

• <strong>The</strong> implicit range : b : c is treated as l : b : c .<br />

• <strong>The</strong> implicit range a : is treated as a :u.<br />

• <strong>The</strong> implicit range a : : c is treated as a :u:c.<br />

One may test whether an integer is in a range by using the operator ∈:<br />

if j ∈ a :b then print “win” end<br />

Ranges may be compared as if they were sets of integers by using ⊂ ( SUBSET ) and ⊆ ( SUBSETEQ ) and = and<br />

⊇ ( SUPSETEQ ) and ⊃ ( SUPSET ).<br />

Nonstrided ranges may be intersected using the operator ∩ ( INTERSECTION ).<br />

<strong>The</strong> size of a range (the number of integers in the set) may be found by using the set-cardinality operator |. . .| . For<br />

example, the value of |3 : 7| is 5 and the value of |1 : 100 :2| is 50 .<br />

Note that a range is very different from an interval with integer endpoints. <strong>The</strong> range 3 :5 contains only the values 3,<br />

4, and 5, whereas the interval [3, 5] contains all real numbers x such that 3 ≤ x ≤ 5 .<br />

13.17 Generators<br />

Syntax:<br />

GeneratorList ::= Generator ( , Generator) ∗<br />

Generator ::= Id ← Expr<br />

| ( Id , IdList ) ← Expr<br />

| Expr<br />

IdList ::= Id ( , Id) ∗<br />

<strong>Fortress</strong> makes extensive use of comma-separated generator lists to express parallel iteration. Generator lists occur in<br />

generated expressions (described in Section 13.11.1), for loops (described in Section 13.15), sums and big operators<br />

(described in Section 13.18), and comprehensions (described in Section 13.29). We refer to these collectively as<br />

expressions with generators. Every expression with generators contains a body expression (for an assignment this<br />

expression is the assignment itself) which is evaluated for each combination of values bound in the generator list.<br />

An element of a generator list is either a generator binding or a boolean expression. A generator binding consists of<br />

one or more comma-separated identifiers followed by the token ← , followed by a subexpression (called the generator<br />

expression). A generator expression evaluates to an object whose type is Generator. For each iteration, a generator<br />

object produces a value or a tuple of values. <strong>The</strong>se values are bound to the identifiers to the left of the arrow, which<br />

are in scope of subsequent generator list elements and of the body of the construct containing the generator list.<br />

A boolean expression in a generator list is interpreted as a filter. An iteration is performed only if the result of the filter<br />

expression is true. If the filter is false, subsequent expressions in the generator list will not be evaluated. However, other<br />

than this restriction, there is no implied order of evaluation of the generator expressions or the boolean expressions in<br />

a generator list. Thus, for example, if a boolean expression in the middle of the list evaluates to true , then generator<br />

expressions to its right in the list may be evaluated before generator expressions to its left.<br />

102

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

Saved successfully!

Ooh no, something went wrong!