Sealing - Spicery/Nutmeg GitHub Wiki
In Nutmeg, every built-in mutable type implements the sealObject method, which modifies the object so that it no longer allow modification. By default, locking is a one-way operation. It is also an opportunity to optimize the object for store.
sealObject{ optimize=LEVEL:number }( OBJECT )
When an object is sealed, if its related objects are all const (fully immutable), then the locked-object will count as const as well.
If the coder believes that optimization is likely to be worth it, they can set a hint to encourage the class to make that optimization, which is an number indicating the order of magnitude that the algorithm should fall below to make this a practical tradeoff. 0 and 1 are intended to be the common options.
| Level | Meaning |
|---|---|
| 0 | Optimization should have a fixed cost |
| 1 | Optimization of O(N) would be OK |
| 2 | Optimization of O(N2) would be OK |
| k | Optimization of O(Nk) would be OK |
| ∞ | Make the optimisation unconditionally |