Ok, maybe we’re tapping somewhere where we shouldn’t… but I’m designing an interface for an object that would really like to be able to access its parent environment as ~parent
.
I understand that when know:true
, setting ~parent
in an Environment will set the parent for real:
a = Environment(parent:currentEnvironment, know: true);
a.use { ~parent = (test: \ok) };
a.test // -> ok
But then why doesn’t envirGet
behave the same?
a = Environment(parent:currentEnvironment, know: true);
a.use { ~parent } // -> nil
And so it doesn’t matter if I try to do a[\parent] = something
: if know
is true
, put
will set the parent
“instance variable”, and envirGet
will still not get it, while at
does though.
a = IdentityDictionary(know: true)
a[\parent] = (test: \ok)
a[\parent] // -> (test: ok)
a.use { ~parent } // -> nil
So it looks like envirPut and envirGet are not “symmetric” in this.
Looking at the source code in LangPrimSource
, envirPut
calls identDictPut
, which checks for know
and parent
and writes to a specific slot:
And prIdentDict_At
also does the same. But envirGet
doesn’t call it, calling instead identDict_lookup
, which doesn’t check for know
and “special fields” at all.
Does anyone know more about this?