Note: information on this page refers to Ceylon 1.0, not to the current release.
Invocation
Invocation is the act of calling something that is
Callable
.
Usage
Invocation using a positional argument list, in parentheses:
put(1, "one")
Invocation using a named argument list, in braces:
put {
integer=1;
name="one;
}
Description
The thing that is being invoked is called the primary of the invocation. It is followed by an argument list.
The type of an invocation expression is the return type of the callable type of the primary. For example, the return type of a function being invoked, or the type of a class being instantiated.
Function and method invocation
Function and method invocation is direct invocation, and therefore supports named argument lists.
Class invocation
Invoking a class (instantiating it) creates a new instance of the class.
Class invocation is a direct invocation, and therefore supports named argument lists.
Indirect invocation
You can invoke a value that has a
Callable
type:
Callable<Anything, []> fn = // ...
Anything result = fn();
Because the Callable
type does not retain any information about
the parameter names, and cannot use a named argument invocation;
only positional arguments.
The Callable
type can encode information about
defaulted parameters, so the
invocation need not specify arguments for parameters which are defaulted:
Callable<Anything, [String=]> defaulted = // ...
variable Anything result = defaulted();
result = defaulted("an argument");
Multiple argument lists
Because a Callable
can itself have a Callable
return type you sometimes see
invocations with multiple parameter lists:
String(String)(Integer) higher = // ...
String result = higher(1)("");
Note that the type abbreviation
for Callable
means that the argument lists appear in
reversed order because String(String)(Integer)
is parsed as Callable<Callable<String, [String]>, [Integer]>
Named argument lists are only allowed as the first argument list in an invocation using multiple argument lists, because the second invocation is an indirect invocation.
Tuple and Iterable enumeration
Technically, tuple and iterable enumerations are also invocations.
See also
- Invocation expressions in the Ceylon language specification