>
|
|
| (2) |
Do some other things, then trigger a collection
>
|
|
The T[1] entry has been removed. The T[z^2] entry's key is referenced in the variable alive, so it stays in the table.
Because table indexing can return unevaluated, it is a common pattern in code to do something like this:
>
|
|
With weak-tables, the entry at T[i] could disappear between the assigned() check and the fetch to assign to val, possibly leading to strange and hard to reproduce errors. There are several ways to safely work around this.
Pattern#1: check assigned and get the value all at once:
>
|
|
Pattern#2: compare against evaln
>
|
|
Pattern#3: use a sparse table
>
|
|
>
|
|
Pattern#4: check that the value is an expected type
>
|
|