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

Idiom # 90: Read-only outside

See programming-idioms.org:

Code

All fields in Fuzion are automatically read-only from inside and form outside. So the task here is more to define a field that is mutable and a way to read this from the outside.

A mutable value has to be created using the mutate effect. mut is a convenience feature to create a mutable value using the current mutate effect.

Running Example

Updating the field from inside does work:

If you analyze the effects used by this code by hitting 'Effects!', you will see that this code uses the mutate effect.

Updating the field from outside will cause a compile-time error:

In any case, the preferred way is not to update a field at all, but to create a new instance:

Note that field f is not updated (which would require the set keyword, but there are two fields called f with a non-overlapping scope.

last changed: 2024-07-01