.method() or ~method().
In Tolk, all methods use a dot: .method(). A method may or may not mutate the object.
Tolk defines a mutability model that generalizes the behavior of the ~ tilde in FunC.
Behavior and semantics differ from FunC.
Tolk method calls are designed to behave similarly to JavaScript:
Value semantics
By default, function arguments in Tolk are copied by value. Function calls do not modify the original data.Mutating function parameters
Adding themutate keyword makes a parameter mutable. To prevent unintended modifications, mutate must also be specified when calling the function.
Instance methods and self
Methods — unlike global functionsfun f() — are declared as fun receiver_type.f().
If a method accepts self, it is an instance method; otherwise, it is static.
self is immutable. The method cannot modify the object.
Mutating methods with self
Combiningmutate with self defines a method that modifies the object and is called using the dot syntax.
Example:
~.
Returning self for chaining
Returningself works as return self in Python or return this in JavaScript. It makes methods such as storeInt() chainable.
self. Omitting it causes a compilation error.
Mutate self in asm functions
The same behavior can also be implemented inasm functions.
A mutation in the compiler works as an implicit return and reassignment of mutate parameters.
Example:
asm function should place self' onto the stack before returning the result: