Fuzion Logo
flang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion LanguageTutorialCalls


Calls are most most important operation in Fuzion. A call to a feature executes the code of a feature and yields the result of that feature.

Simple Calls

A call typically has the form

  target.calledFeature arguments
  target.calledFeature arguments

where target itself is a call that determines the instance the call is executed on and arguments specify the initial values of the argument fields of the called feature.

If target is not given, target is the instance of the current feature or, in case this feature does not declare a feature named calledFeaturecalledFeature.

Here is s small example that defines and calls the features double, pow and lastDigit on instances of MyInt:

After the declaration of myInt, the example starts by calling myInt(7) and assigning the result to a new field seven. This call does not specify an explicit target, the implicit target is the current instance, the argument field v will be initialized to 7.

A feature that does not define an explicit result type (or uses => and type inference to infer the result type) implicitly returns its current instance as a result. So in the case of the call g myInt(7), the result is an instance of myInt with the field v set to 7.

Next, the call seven.minus1 is performed. The target of the call is the value stored in field seven. There are no arguments expected by minus1, so none are given tot he call and parentheses are also not needed. The result of the call to minus1 is a new instance of myInt.

The following call six.pow(3) calls pow on the target six given the argument 3. If you look at the code of pow, you can see that it takes the current object to the given exponent using a recursive call to itself.

Finally, at the end of this example, six.factorial calls factorial on six.

For clarity, the previous example did not use syntactic sugar. It can be simplified to equivalent code as follows:


The use of any operator such as infix + to add numeric values is a call to a feature. To define an operator, the feature name must be infix, prefix, or postfix followed by the operator to define.

Here is the same example as above using prefix, infix and postfix operators instead of normal feature names:

The use of operators as feature names is purely syntactic, the code is equivalent to the version using normal names.

It is even possible to use dot-notation for calls to features whose name is an operator. E.g., the call --seven is equivalent to seven.prefix --:

next: Lazy Evaluation