kdb:解析"x [y]"的类型是什么? [英] kdb: what is the type of parse"x[y]"?

查看:45
本文介绍了kdb:解析"x [y]"的类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于表达式 parse"x [y]" ,我认为这表示对参数 y x 的函数/映射/列表应用>,可能是投影.如果我错了,请纠正我.

For expression parse"x[y]", I think it means a function/map/list application of x on argument y, possibly a projection. Please correct me if I'm wrong.

现在进入Q控制台,我得到以下输出.

Now entering into Q console, I get below output.

q)parse"x[y]"
x
y
q)l:parse"x[y]"
q)count l
2
q)type l
0h
q)l[0]
`x
q)l[1]
`y
q)type l[0]
-11h
q)type l[1]
-11h

我们看到 l 的类型为 0h .它的长度为2.两个元素的类型均为 -11h .为什么是列表,而不是 11h 类型?

We see l has type 0h. It has length 2. Both elements have type -11h. Why is the list then, not of type 11h?

推荐答案

简而言之,它是一个解析树签名'type'构造,与lambda(类型为64)非常相似.当对象到达调用堆栈时, k 会在解析树中识别并评估表达式,从而取消引用符号的作用,就像指针一样.

In short, it's a parse tree signature 'type' construct, very similar to lambda (which would be type 64). k recognises and evaluates expression in parse tree when object reaches call stack, de-referencing symbols-which acts like a pointer.

TL; DR -逐步细分

  1. 基本评估结构

"x [y]"〜"x y"

q)x:count
q)y: 1 2 3
q)parse "x y"  
x
y
q)x y
3
q)`x y
3
q)eval parse "x y"
3

简单索引,简化" 第二个参数->内部原子:

Simple indexing, 'simplified' 2nd param -> int atom:

q)parse "y 2"  //this nicely shows parse tree
`y
2
q)eval parse "y 2" 
3 
q)eval (`y;2)
3 
q)`y 2
3
q)y 2
3

以上两个示例都是混合列表(0h),实际元素紧随其后-其中符号是引用.而是使用普通的混合列表构造,以后将定义所有长度和类型

Both above examples are mixed lists (0h), with actual elements following immediately - where symbols - are references. Instead with normal mixed list construct where all lenghts and types are defined later

  1. 着眼于序列化的IPC框架有助于理解这种结构

确定哪些表达式相同

q)parse["x[y]"] ~ parse "x y"
1b
q)parse["x[y]"] ~ parse "x@y"
0b
q)parse["x[y]"] ~ parse "{x y}" 
0b

比较字节帧

q)-8!parse "x[y]" 
0x0100000014000000000002000000f57800f57900
q)-8!parse "x y"  
0x0100000014000000000002000000f57800f57900  
q)-8!`x`y 
0x01000000120000000b000200000078007900 
q)-8!enlist `x`y
0x01000000180000000000010000000b000200000078007900 
                                                                                                                 

将第一段的解析树输出与实际obj而不是引用进行比较

q)-8!parse "x y"
0x0100000014000000000002000000f57800f57900 
q)-8!parse "x 2"
0x010000001a000000000002000000f57800f90200000000000000

Lambda结构以完成列表以供参考

q)-8!{x y}
0x010000001500000064000a00050000007b7820797d
/0x7b "{" ; 0x7d "}"

  1. 最后是IPC框架故障

`x`y(符号列表)

q)symlist:`endian`isync`x`y`length`type`attr`msg!sums[0 1 1 1 1 4 1 1] _ -8!`x`y
q)symlist
 endian| ,0x01     (little endian)    
 isync | ,0x00 
 x     | ,0x00   
 y     | ,0x00 
 length| 0x12000000 
 type  | ,0x0b     (11h - symbol list - 1st difference)
 attr  | ,0x00  
 msg   | 0x0200000078007900   

深入研究对称列表:

  q)msg:`lenght`msg!sums[0 4] _ symlist`msg 
  q)msg
   lenght| 0x02000000
   msg   | 0x78007900
                                                                                                                 

在这里我们可以清楚地看到,由于显式类型:0x0b-11h-符号列表,空终止符号如何立即跟随向量的长度

Here we can clearly see, how null terminated symbol follows length of vector immediately, due to explicit type: 0x0b - 11h - symbol list

  q)`char$msg`msg
   "x\000y\000"

解析"x [y]";-解析树故障

q)o1:`endian`isync`x`y`length`type`attr`msg!sums[0 1 1 1 1 4 1 1]_ -8!parse"x[y]"
q)o1   
 endian| ,0x01            
 isync | ,0x00   
 x     | ,0x00 
 y     | ,0x00   
 length| 0x14000000    
 type  | ,0x00   (could expect 64 - 100h lambda)
 attr  | ,0x00    
 msg   | 0x02000000f57800f57900   

与简单列表的区别:

   q)`lenght`type1`msg1`type2`msg2!sums[0 4 1 2 1 ] _ o1`msg
    lenght| 0x02000000
    type1 | ,0xf5        (-11h - symbol atom) - acts as a reference
    msg1  | 0x7800       null terminated "x" 
    type2 | ,0xf5        (-11h - symbol atom)
    msg2  | 0x7900       null terminated "y"  - acts as a reference

这篇关于kdb:解析"x [y]"的类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆