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 dotted method invocation consists of a subexpression (called the receiver expression), followed by ‘.’, followed by<br />

an identifier, an optional list of type arguments (described in Chapter 12) and a subexpression (called the argument<br />

expression). Unlike in function calls (described in Section 13.6), the argument expression must be parenthesized, even<br />

if it is not a tuple. <strong>The</strong>re must be no whitespace on either side of the ‘.’, and there must be no whitespace on the<br />

left-hand side of the left parenthesis of the argument expression. <strong>The</strong> receiver expression evaluates to the receiver of<br />

the invocation (bound to the self parameter (discussed in Section 9.2) of the method). A coercion invocation (discussed<br />

in Chapter 17) has a similar syntax to a dotted method invocation.<br />

<strong>The</strong> subexpressions of a method invocation are evaluated in parallel; evaluation steps of the subexpressions can be<br />

interleaved, and even reordered, to form an evaluation of the method invocation. See Section 4.4 for a discussion of the<br />

semantics of their concurrent evaluation. A method invocation may include explicit instantiations of type parameters<br />

but most method invocations do not include them; the type arguments are statically inferred from the context of the<br />

method invocation (as described in Chapter 20). After the subexpressions of a dotted method invocation are evaluated<br />

to values, the body of the method is evaluated with the parameter of the method bound to the value of the argument<br />

expression. <strong>The</strong> value and the type of a dotted method invocation are the value and the type of the method body.<br />

We say that methods or functions (collectively called as functionals) may be applied to (also “invoked on” or “called<br />

with”) an argument. We use “call”, “invocation”, and “application” interchangeably.<br />

Here are some examples:<br />

myString.toUppercase()<br />

myString.replace(“foo”, “few”)<br />

SolarSystem.variation((π/2 radian)/452million year)<br />

myNum.add(otherNum) (∗ NOT myNum.add otherNum ∗)<br />

13.5 Naked Method Invocations<br />

Syntax:<br />

Expr ::= Id Expr<br />

Method invocations that are not prefixed by receivers are naked method invocations. A naked method invocation is<br />

either a functional method call (See Section 9.2 for a discussion of functional methods) or a method invocation within<br />

a trait or object that provides the method declaration. Syntactically, a naked method invocation is same as a function<br />

call except that the method name is used instead of an arbitrary expression denoting the applied method. Like function<br />

calls, an argument expression need not be parenthesized unless it is a tuple. After the argument expression is evaluated<br />

to a value, the body of the method is evaluated with the parameter of the method bound to the value of the argument<br />

expression. <strong>The</strong> value and the type of a naked method invocation are the value and the type of the method body.<br />

13.6 Function Calls<br />

Syntax:<br />

Expr ::= Expr Expr<br />

A function call consists of two subexpressions: an expression denoting the applied function and an argument expression.<br />

<strong>The</strong> argument expression and the expression denoting the applied function are evaluated in parallel: evaluation<br />

steps of the subexpressions can be interleaved, and even reordered when forming an evaluation of the function call.<br />

See Section 4.4 for a description of the semantics of parallel evaluation. As with languages such as Scheme and the<br />

Java Programming <strong>Language</strong>, function calls in <strong>Fortress</strong> are call-by-value. An argument expression is evaluated to a<br />

value before the function is applied. After the subexpressions of a function call are evaluated to values, the body of<br />

94

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

Saved successfully!

Ooh no, something went wrong!