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.

while x < 10 do<br />

print x<br />

x += 1<br />

end<br />

Blocks in <strong>Fortress</strong> are delimited by the special reserved words do and end . Here is an example of a function that<br />

prints three words:<br />

printThreeWords() = do<br />

print “print”<br />

print “three”<br />

print “words”<br />

end<br />

A tuple expression contains a sequence of elements delimited by parentheses and separated by commas:<br />

(“this”, “is”, “a”, “tuple”, “of”, “mostly”, “strings”, 0)<br />

When a tuple expression is evaluated, the various subexpressions are evaluated in parallel. For example, the following<br />

tuple expression denotes a parallel computation:<br />

(factorial(100),factorial(500),factorial(1000))<br />

<strong>The</strong> elements in this expression may be evaluated in parallel.<br />

2.8 For Loops Are Parallel by Default<br />

Here is an example of a simple for loop in <strong>Fortress</strong>:<br />

for i ← 1 : 10 do<br />

print(i “ ”)<br />

end<br />

This for loop iterates over all elements i between 1 and 10 and prints the value of i . Expressions such as 1 : 10<br />

are referred to as range expressions. <strong>The</strong>y can be used in any context where we wish to denote all the integers between<br />

a given pair of integers.<br />

A significant difference between <strong>Fortress</strong> and most other programming languages is that for loops are parallel by<br />

default. Thus, printing in the various iterations of this loop can occur in an arbitrary order, such as:<br />

5 4 6 3 7 2 9 10 1 8<br />

2.9 Atomic Expressions<br />

In order to control interactions of parallel executions, <strong>Fortress</strong> includes the notion of atomic expressions, as in the<br />

following example:<br />

atomic do<br />

x += 1<br />

y += 1<br />

end<br />

25

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

Saved successfully!

Ooh no, something went wrong!