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.

Here are examples of function declarations whose bodies are do expressions:<br />

f(x : R64) = do<br />

(sin(x) + 1) 2<br />

end<br />

foo(x : R64) = do<br />

y = x<br />

z = 2x<br />

y + z<br />

end<br />

mySum(i : Z64) : Z64 = do<br />

acc : Z64 := 0<br />

for j ← 0 : i do<br />

acc := acc + j<br />

end<br />

acc<br />

end<br />

13.11.1 Generated Expressions<br />

If a subexpression of a do expression has type (), the expression may be followed by a ‘ , ’ and a generator list<br />

(described in Section 13.17). When a generator list is provided, generators produce values and bind the values to the<br />

identifiers that are used in the preceding expression. Most generators, unlike the sequential generator, may execute<br />

each evaluation of the assignment in a separate implicit thread.<br />

13.11.2 Distinguishing a Local Declaration from an Equality Expression<br />

Because a local declaration shares a syntax with an equality expression, we provide rules for disambiguation:<br />

• If an expression of the form “e = e ” occurs as a proper subexpression in any non-block expression, it is an<br />

equality expression.<br />

• If such an expression occurs as an immediate subexpression of a block expression, it is a local declaration.<br />

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

13.12 Parallel Do Expressions<br />

Syntax:<br />

Do ::= do BlockElem + also Do<br />

| at Expr Do<br />

A series of blocks may be run in parallel using the also do construct. Any number of contiguous blocks may be<br />

joined together by the special reserved word also . Each block is run in a separate implicit thread; these threads<br />

together form a group. A thread can be placed in a particular region by using an at expression as described in<br />

Section 32.7.<br />

For example:<br />

98

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

Saved successfully!

Ooh no, something went wrong!