关于 xkey 实现
About xkey implementation
函数式应用方法 .[0!y;();xcols x]
之间的区别是什么,参见 xkey
:
xkey
k){(#x)!.[0!y;();xcols x]}
和一个简单的函数调用:x xcols 0!y
.
为什么在xkey
中首选函数apply?
关于从 k)
上下文内部调用 xcols
的第二个问题 - 它是如何工作的?由于某种原因我不能这样做:
t:([]a:`a`s`d;b:1 2 3;c:4 5 6)
k).[0!t;();xcols `a`b]
ERROR: 'xcols
(attempt to use variable xcols without defining/assigning first (or user-defined signal))
我认为函数式应用可能适用于按名称传递 table 时
t:([]a:`a`s`d;b:1 2 3;c:4 5 6)
.[0!t;();xcols[`a`b]] /this works
`a`b xcols 0!t /equivalent non functional form works
q)`a`b xcols 0!`t /this fails when passing `t
'type
[0] `a`b xcols 0!`t
q).[0!`t;();xcols[`a`b]] /though functional form still works with `t
q)`a`b xkey `t /hence you can use xkey in place
`t
编辑:
为了将我的评论包含在完整性的答案中,当在 k 中时,您应该在 q 命令前加上 .q 以访问它们,因为这是它们所在的命名空间
q)xcols[`a`b]
k){(x,f@&~(f:cols y)in x)#y}[`a`b]
q)\
.q.xcols`a`b
k){(x,f@&~(f:cols y)in x)#y}[`a`b]
编辑 2:
为了解决您的评论,您的示例的 xcols 归结为
`a`b`c#t
和
`a`b`c#`t
不起作用。我没有太多解释为什么它不起作用,除了它是如何设计的。函数形式告诉 q 通过应用 take 函数修改 table。但是上面的示例不是用于将 table 重新定义为其列的 re-ordering 的公认语法。
函数式应用方法 .[0!y;();xcols x]
之间的区别是什么,参见 xkey
:
xkey
k){(#x)!.[0!y;();xcols x]}
和一个简单的函数调用:x xcols 0!y
.
为什么在xkey
中首选函数apply?
关于从 k)
上下文内部调用 xcols
的第二个问题 - 它是如何工作的?由于某种原因我不能这样做:
t:([]a:`a`s`d;b:1 2 3;c:4 5 6)
k).[0!t;();xcols `a`b]
ERROR: 'xcols
(attempt to use variable xcols without defining/assigning first (or user-defined signal))
我认为函数式应用可能适用于按名称传递 table 时
t:([]a:`a`s`d;b:1 2 3;c:4 5 6)
.[0!t;();xcols[`a`b]] /this works
`a`b xcols 0!t /equivalent non functional form works
q)`a`b xcols 0!`t /this fails when passing `t
'type
[0] `a`b xcols 0!`t
q).[0!`t;();xcols[`a`b]] /though functional form still works with `t
q)`a`b xkey `t /hence you can use xkey in place
`t
编辑: 为了将我的评论包含在完整性的答案中,当在 k 中时,您应该在 q 命令前加上 .q 以访问它们,因为这是它们所在的命名空间
q)xcols[`a`b]
k){(x,f@&~(f:cols y)in x)#y}[`a`b]
q)\
.q.xcols`a`b
k){(x,f@&~(f:cols y)in x)#y}[`a`b]
编辑 2: 为了解决您的评论,您的示例的 xcols 归结为
`a`b`c#t
和
`a`b`c#`t
不起作用。我没有太多解释为什么它不起作用,除了它是如何设计的。函数形式告诉 q 通过应用 take 函数修改 table。但是上面的示例不是用于将 table 重新定义为其列的 re-ordering 的公认语法。