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> rules below are designed to forbid certain forms of notational ambiguity that can arise if the name of a functional<br />

method happens to be used also as the name of a variable. For example, suppose that trait T has a functional method<br />

of one parameter named n ; then in the code<br />

do<br />

a: T = t<br />

n: Z = 14<br />

z = na<br />

end<br />

it might not be clear whether the intended meaning was to invoke the functional method n on a or to multiply a by<br />

14 . <strong>The</strong> rules specify that such a situation is a static error.<br />

<strong>The</strong> rules for reassociating a loose juxtaposition are as follows:<br />

• First the loose juxtaposition is broken into nonempty chunks; wherever there is a non-function element followed<br />

by a function element, the latter begins a new chunk. Thus a chunk consists of some number (possibly zero) of<br />

functions followed by some number (possibly zero) of non-functions.<br />

• It is a static error if any non-function element in a chunk is an unparenthesized identifier f and is followed by<br />

another non-function element whose type is such that f can be applied to that latter element as a functional<br />

method.<br />

• <strong>The</strong> non-functions in each chunk, if any, are replaced by a single element consisting of the non-functions grouped<br />

left-associatively into binary juxtapositions.<br />

• What remains in each chunk is then grouped right-associatively.<br />

• It is a static error if an element of the original juxtaposition was the last element in its chunk before reassociation,<br />

the chunk was not the last chunk (and therefore the element in question is a non-function element), the element<br />

was an unparenthesized identifier f , and the type of the following chunk after reassociation is such that f can<br />

be applied to that following chunk as a functional method.<br />

• Finally, the sequence of rewritten chunks is grouped left-associatively.<br />

(Notice that no analysis of the types of newly constructed chunks is needed during this process.)<br />

Here is an example: n (n + 1) sin 3 n x log log x . Assuming that sin and log name functions in the usual manner<br />

and that n , (n + 1) , and x are not functions, this loose juxtaposition splits into three chunks: n (n + 1) and<br />

sin 3 n x and log log x . <strong>The</strong> first chunk has only two elements and needs no further reassociation. In the second<br />

chunk, the non-functions 3 n x are replaced by ((3 n) x) . In the third chunk, there is only one non-function,<br />

so that remains unchanged; the chunk is the right-associated to form (log (log x)) . Finally, the three chunks are<br />

left-associated, to produce the final interpretation ((n (n + 1)) (sin ((3 n) x))) (log (log x)) . Now the original juxtaposition<br />

has been reduced to binary juxtaposition expressions.<br />

<strong>The</strong> rules for reassociating a tight juxtaposition follow a different strategy:<br />

• If the tight juxtaposition contains no function element, or if only the last element is a function, go on to the<br />

next step. Otherwise, consider the leftmost function element and examine the element that follows it. If that<br />

latter element is not parenthesized, it is a static error; otherwise, replace the two elements with a single element<br />

consisting of a new juxtaposition of the two elements (in the same order), and perform a type analysis on this new<br />

juxtaposition. (At this point, it is a static error if this new juxtaposition is preceded in the overall juxtaposition<br />

by a non-function element that is an unparenthesized identifier f , and the type of the new juxtaposition is such<br />

that f can be applied to it as a functional method.) <strong>The</strong>n repeat this step on the original juxtaposition (which is<br />

now one element shorter).<br />

• <strong>The</strong> overall juxtaposition now either is a single element or consists entirely of non-function elements. It is a<br />

static error the overall juxtaposition now contains a non-function element that is an unparenthesized identifier<br />

f , and the type of the following element is such that f can be applied to it as a functional method.<br />

131

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

Saved successfully!

Ooh no, something went wrong!