簡體   English   中英

受保護的執行,2 例

[英]Protected execution, 2 cases

為什么在第一個受保護的情況下執行工作,但在第二個沒有?:

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

受保護的執行正在使用您提供的參數。 前兩個示例是預測,但最后一個不是,因此執行失敗。

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中,使@ apply 成為 function 會強制使用受保護執行中的參數。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM