Mutability in Tolk vs tilda functions in FunC
TLDR
- no
~
tilda methods cs.loadInt(32)
modifies a slice and returns an integerb.storeInt(x, 32)
modifies a builderb = b.storeInt()
also works, since it not only modifies, but returns- chained methods work identically to JS, they return
self
- everything works exactly as expected, similar to JS
- no runtime overhead, exactly same Fift instructions
- custom methods are created with ease
- tilda
~
does not exist in Tolk at all
This is a drastic change. If FunC has .methods()
and ~methods()
, Tolk has only dot, one and only way to call a .method()
. A method may mutate an object, or may not. Unlike the list "in short", it's a behavioral and semantic difference from FunC.
The goal is to have calls identical to JS and other languages:
FunC | Tolk |
---|---|
int flags = cs~load_uint(32); | var flags = cs.loadUint(32); |
(cs, int flags) = cs.load_uint(32); | var flags = cs.loadUint(32); |
(slice cs2, int flags) = cs.load_uint(32); | var cs2 = cs; |
slice data = get_data() | val flag = getContractData() |
dict~udict_set(...); | dict.uDictSet(...); |
b~store_uint(x, 32); | b.storeInt(x, 32); |
b = b.store_int(x, 32); | b.storeInt(x, 32); |
b = b.store_int(x, 32) | b.storeInt(x, 32) |
In order to make this available, Tolk offers a mutability conception, which is a generalization of what a tilda means in FunC.
By default, all arguments are copied by value (identical to FunC)
fun someFn(x: int) {
x += 1;
}
var origX = 0;
someFn(origX); // origX remains 0
someFn(10); // ok, just int
origX.someFn(); // still allowed (but not recommended), origX remains 0