After debugging a large chunk of code, I could identify this MWE.
ClearAll@test
test[var_String]:= Block[{association},
association = <|"x"-> <|"key01"-> "ok"|>|>[var];
Lookup[association,"key01",{}]
]
If I evaluate:
test["x"]
test["y"]
test["x"]
I get an error evaluating the last test["x"]
. What is very strange, I expected to find an error just in the evaluation of test["y"]
.
The same error does not occur if we change from Block
to Module
. In the Block
case, we have some sort of unexpected scope leak. Is this a bug?
Tested in Mathematica version 11.3
Cross post in Mathematica Community
Still bugged in version 12.1
Lookup
has the attributeHoldAllComplete
, which means it sees the symbolassociation
, not its value. I don't think the bug is inBlock
. $\endgroup$Associations
. It looks likeLookup
is remembering something perhaps.Lookup
being the newer thing, I suspect it overBlock
; but I don't know for sure. Hopefully someone who knows more can explain. -- I guess it's clear it's the combination of both, since using a globalassociation
doesn't suffer the same problem. $\endgroup$Lookup
. I note that if we evaluateUpdate[Lookup]
to flush its hidden caches, thentest["x"]
starts working again. $\endgroup$Module
because running a second time creates a new instantiation ofassociation
.In[1]:= Table[Module[{x}, x], 2] Out[1]= {x$5672, x$5673}
. $\endgroup$