【问题标题】:Protected execution, 2 cases保护执行,2 例
【发布时间】:2021-01-18 11:23:49
【问题描述】:

为什么在第一种情况下受保护的执行工作,但在第二种情况下却没有?:

q)t:([]a:1 2;b:3 4);
q)@[@[cols t; ; :; `bb]; (cols t)?`b; `columnNotFound]
`a`bb
q)@[@[cols t; ; :; `cc]; (cols t)?`c; `columnNotFound] // 1. works perfectly
`columnNotFound
q)@[@[cols t; (cols t)?`c; :; `cc]; `; `columnNotFound] // 2. exception does not handled
'length
  [0]  @[@[cols t; (cols t)?`c; :; `cc]; `; `columnNotFound]
         ^

更新:

嗯,我尝试后怀疑:

q)@[{@[cols t; (cols t)?`c; :; `cc]}; `; `columnNotFound]
`columnNotFound

【问题讨论】:

    标签: kdb k


    【解决方案1】:

    受保护的执行正在使用您提供的参数。前两个示例是预测,但最后一个不是,因此执行失败。

    q){@[cols t;x;:;`bb]}(cols t)?`b
    `a`bb
    q){@[cols t;x;:;`cc]}(cols t)?`c  / thrown into error trap
    'length
      [1]  {@[cols t;x;:;`cc]}
            ^
    q))\
    q)@[cols t;(cols t)?`c;:;`cc]     / fails on execution
    'length
      [0]  @[cols t;(cols t)?`c;:;`cc]
           ^
    q)
    

    在您的 upd 中,使 @ 应用函数会强制使用受保护执行中的参数。

    q){@[cols t;(cols t)?`c;:;`cc]}`
    'length
      [1]  {@[cols t;(cols t)?`c;:;`cc]}
            ^
    q))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-29
      • 1970-01-01
      相关资源
      最近更新 更多