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.

• a parameter list with a varargs binding, provided that<br />

– type A has at least as many plain types as the parameter list has plain bindings, and<br />

– for every keyword-type pair in A, the parameter list has a binding with the same keyword, and<br />

– for every element type in A, the type in the element type is a subtype of the type of the corresponding<br />

binding in the parameter list—but if there is no corresponding binding, then the type in the element type<br />

must be a subtype of the type in the varargs binding.<br />

In the latter case, the parameter named by the identifier in the varargs binding is bound to a HeapSequenceT that<br />

contains, in order, all the values of the tuple that did not correspond to plain bindings, followed by all the values in the<br />

varargs HeapSequence of the tuple, if any.<br />

When an argument is passed explicitly for a keyword parameter, that argument must be passed as a keyword argument.<br />

Syntactically, a keyword argument is a keyword-value pair “identifier = e ”. Keyword parameters not explicitly<br />

bound are bound to their default values. If a parameter that has no default value is not explicitly bound to an argument,<br />

it is a static error. Because a keyword-value pair shares a syntax with an equality expression, we provide rules for<br />

disambiguation in Section 13.28.1.<br />

When a function is called (See Section 13.6 for a discussion of function call expressions), explicit arguments are<br />

evaluated in parallel, keyword parameters not explicitly bound are bound to their default values sequentially, and the<br />

body of the function is evaluated in a new environment, extending the environment in which it is defined with all<br />

parameters bound to their arguments.<br />

If the application of a function f ends by calling another function g , tail-call optimization must be applied. Storage<br />

used by the new environments constructed for the application of f must be reclaimed.<br />

Here are some examples:<br />

sqrt(x)<br />

arctan(y, x)<br />

makeColor(red = 5,green = 3,blue = 43)<br />

processString(s,start = 5,finish = 43)<br />

If the function’s argument is not a tuple, then the argument need not be parenthesized:<br />

sqrt 2<br />

sin x<br />

log log n<br />

Here are a few varargs examples:<br />

f(x : Z, y : Z, z : Z . . .) = 〈x, y, 〈q | q ← z〉〉<br />

f(1, 2) returns 〈1, 2, 〈〉〉<br />

f(1, 2, 3, 4) returns 〈1, 2, 〈3, 4〉〉<br />

f(1, 2, [3 4] . . .) returns 〈1, 2, 〈3, 4〉〉<br />

f(1, 2, 3, 4, [5 6] . . .) returns 〈1, 2, 〈3, 4, 5, 6〉〉<br />

f(1, 2, 3, 4, 17 #3...) returns 〈1, 2, 〈3, 4, 17, 18, 19〉〉<br />

f(1, [3 4] . . .) declaration not applicable<br />

12.3 Abstract Function Declarations<br />

Syntax:<br />

AbsFnDecl ::= FnMod ∗ FnHeader<br />

| Name : ArrowType<br />

88

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

Saved successfully!

Ooh no, something went wrong!