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


So far, we have seen features that were implemented as routines. An alternative to implementing a feature as a routine is implementing it as a field.

Argument Fields

Let us start with a small example that declares a feature Point with two arguments x and y of type i32, which is a 32-bit signed integer value:
The arguments x and y are inner features of Point. Argument features are always fields. Fields can store a value.

Next, the example declares two fields p1 and p2 of type . Two instances of Point with values 3, 4 and 5, 12, are then created by calls to Point with these values passed as actual arguments.

These two instances of Point are assigned to fields p1 and p2.

Finally, these points are passed to a routine show that calls Point.x and Point.y on its argument px and y.

Fuzion's syntax permits some simplifications of this code. First, an initial value can be assigned to a field directly at the point of declaration:

Additionally, the result type of a field can be omitted if := is used to assign the initial value. The type will then be inferred from the expression provided as initial value: