1 # Heap Allocation with `@`
5 # By default, values in Tomo are immutable.
6 # To allow mutation, you need to allocate memory using `@`
16 # Allocated memory is not equal to other allocated memory:
19 pointers_are_equal := (a == b)
20 assert pointers_are_equal == ???
22 # The `[]` operator can be used to access the value stored
23 # at a memory location:
24 contents_are_equal := (a[] == b[])
25 assert contents_are_equal == ???
27 # Tables also require `@` to allow modifications:
28 scores := @{"Alice": 100, "Bob": 200}
30 scores["Charlie"] = 300
32 assert scores["Charlie"] == ???
34 # Without `@`, attempting to mutate will cause an error:
35 frozen := {"key": "value"}
36 frozen["key"] = "new value" # <- This will break, comment it out
38 assert frozen["key"] == "value"