请帮助我理解 jsonnet 规范中的 local-var 规则:
我想总体了解它,但具体来说,它如何应用于jsonnet参考手册中找到的以下程序?
local a = local x = 'a'; x;
local foo = local x = 'b'; a;
foo
免责声明:此回复来自我的
jsonnet
实用经验,我几乎无法阅读(如果有的话)语言规范。
我是这样理解的:本地作用域由
local
打开(在其他语言中,如 {
认为 if 为
C
),并由 ;
关闭(类似于 }
)
下面的示例基于您的示例,但添加缩进+注释以突出显示嵌套位置“级别”:
local a =
// level0 scope
local x =
// level1 scope
local y =
// level2 scope
local z = '.';
'1' + z;
'a' + y; // `z` here would be outside of scope
x; // `y` here would be outside of scope
local foo =
// level0 scope
local x =
// level1 scope
local y =
// level2 scope
local z = ',';
'2' + z;
'b' + y; // `z` here would be outside of scope
a + x; // `y` here would be outside of scope
foo