This is achieved by a lack of global variables and all function arguments being immutable by default, even when are passed.
V is not a purely functional language however.
It is possible to modify function arguments by using the keyword mut
:
In this example, the receiver (which is simply the first argument) is marked as mutable, so can change the user object. The same works with non-receiver arguments:
It is preferable to return values instead of modifying arguments. Modifying arguments should only be done in performance-critical parts of your application to reduce allocations and copying.
For this reason V doesn’t allow the modification of arguments with primitive types (e.g. integers). Only more complex types such as arrays and maps may be modified.
V makes it easy to return a modified version of an object: