3 ms·
self should refer to the immediately containing object, the outermost object should be called top (or whatever). Or perhaps found relatively with self.out.out.o
by kazinator 4y ago
self should refer to the immediately containing object, the outermost object should be called top (or whatever). Or perhaps found relatively with self.out.out.out...
Imagine having to take a nested configuration fragment that refers to its own pieces via the absolute self, and trying to plant it in some other configuration, at a different nesting level.
- q3k 4y ago> Or perhaps found relatively with self.out.out.out Jsonnet’s internal predecessor /counterpart/inspiration (Google BCL/GCL) has something like this and not including it in Jsonnet is a feature :).
- ithkuil 4y agoyep, mixing lexical and dynamic scope was the hell indeed. A convention I use with jsonnet is to use locals to "anchor" some important objects in the lexical scope. My rule is to name the locals with exactly the same name as the field whose object they refer to. Example: { deployment: { local deployment = self, spec+: { replicas: 3, template+: { spec+: { local spec = self, containers: [ { name: 'foo', env: [ { name: 'REP', value: std.toString(deployment.spec.replicas) }, { name: 'SA', value: spec.serviceAccountName }, ], }, ], serviceAccountName: 'foo', } }, }, }, } Adding these locals gives the right amount of friction to avoid using this all the time, while at the same time having a predictable naming for the locals. The jsonnet LSP tool can easily resolve that local since it's only a lexical thing