@ 和 之间的区别。在kdb中修改
Difference between @ and . amend in kdb
我在 KX wiki 上阅读了一些关于 @ 修改的内容,其中指出:
@
(amend)
Syntax: @[x;i;f]
Syntax: @[x;i;f;a]
Syntax: @[x;i;f;v]
Functional amend Where
x
is a list (or file symbol, see Tip)
i
is an int vector of indexes of x
f
is a function
a
is an atom in the domain of the second argument of f
v
is a vector in the domain of the second argument of f
弄乱 @
和 .
,它们的行为似乎相似,我尝试使用空列表代替索引,发现每个列表的处理方式不同:
q)a
1 2 3
q)@[a;();+;100]
1 2 3
q).[a;();+;100]
101 102 103
似乎 @
使用 ()
相当于 'no indices',使用 .
相当于 'all indices'。为什么会出现这种截然不同的行为?
差异可以归结为两个修正的嵌套级别。 .
用于多层嵌套,@
用于单层(列表)。通过在使用 .
时将 enlist
与索引一起使用,我们嵌套索引并为您提供的 a
之类的简单列表获得相同的输出:
q)a
1 2 3
q)@[a;();+;100]
1 2 3
q).[a;enlist();+;100]
1 2 3
q)@[a;(::);+;100]
101 102 103
q).[a;enlist(::);+;100]
101 102 103
q)@[a;1 2;+;100]
1 102 103
q).[a;enlist 1 2;+;100]
1 102 103
将()
与.
一起使用等同于入伍的空函数(::)
。
需要注意的是,这种关系适用于复杂列表:
q)show m:3 cut 1+til 9
1 2 3
4 5 6
7 8 9
q)@[m;1 2;+;100]
1 2 3
104 105 106
107 108 109
q).[m;enlist 1 2;+;100] / nest with enlist
1 2 3
104 105 106
107 108 109
q).[m;(1 2;::);+;100] / nest with null func
1 2 3
104 105 106
107 108 109
我在 KX wiki 上阅读了一些关于 @ 修改的内容,其中指出:
@
(amend)Syntax:
@[x;i;f]
Syntax:@[x;i;f;a]
Syntax:@[x;i;f;v]
Functional amend Where
x
is a list (or file symbol, see Tip)
i
is an int vector of indexes ofx
f
is a function
a
is an atom in the domain of the second argument off
v
is a vector in the domain of the second argument off
弄乱 @
和 .
,它们的行为似乎相似,我尝试使用空列表代替索引,发现每个列表的处理方式不同:
q)a
1 2 3
q)@[a;();+;100]
1 2 3
q).[a;();+;100]
101 102 103
似乎 @
使用 ()
相当于 'no indices',使用 .
相当于 'all indices'。为什么会出现这种截然不同的行为?
差异可以归结为两个修正的嵌套级别。 .
用于多层嵌套,@
用于单层(列表)。通过在使用 .
时将 enlist
与索引一起使用,我们嵌套索引并为您提供的 a
之类的简单列表获得相同的输出:
q)a
1 2 3
q)@[a;();+;100]
1 2 3
q).[a;enlist();+;100]
1 2 3
q)@[a;(::);+;100]
101 102 103
q).[a;enlist(::);+;100]
101 102 103
q)@[a;1 2;+;100]
1 102 103
q).[a;enlist 1 2;+;100]
1 102 103
将()
与.
一起使用等同于入伍的空函数(::)
。
需要注意的是,这种关系适用于复杂列表:
q)show m:3 cut 1+til 9
1 2 3
4 5 6
7 8 9
q)@[m;1 2;+;100]
1 2 3
104 105 106
107 108 109
q).[m;enlist 1 2;+;100] / nest with enlist
1 2 3
104 105 106
107 108 109
q).[m;(1 2;::);+;100] / nest with null func
1 2 3
104 105 106
107 108 109