0

t1请通过以下路径帮助我进行转型:

t1:enlist `a`b!1 2;
t2:exec val from ([]val:t1);
-3!t1    // +`a`b!(,1;,2)
-3!t2    // ,`a`b!1 2
t1~t2[;] // 1b

我希望第二行 ( exec) 返回与 相同的对象t1,但事实并非如此。出于某种原因,[;]只能t1t2.

那么第 2 行和第 5 行发生了什么(以及为什么)?


UPD 为什么enlist如此富有成效?它对每个元素进行登记,翻转整个对象

-3!enlist `a`b!1 2           // +`a`b!(,1;,2)
-3!enlist each `a`b!1 2      //  `a`b!(,1;,2)
-3!flip enlist each `a`b!1 2 // +`a`b!(,1;,2)
4

1 回答 1

1

我认为这里发生的事情是,当它成为表的列时,将(符合)字典列表的特殊提升到表本质上是“撤消”的。它可以追溯到字典列表,就好像它们不符合要求一样,尽管终端仍然会误导地显示它,就好像它是一个表格一样。要看到这一点,请考虑以下示例:

/promoted to table
q)-3!(`a`b!4 5;`a`b!1 2)
"+`a`b!(4 1;5 2)"
/still a table (embedded)
q)-3!enlist(`a`b!4 5;`a`b!1 2)
",+`a`b!(4 1;5 2)"
/still a table (embedded)
q)-3!(1#`val)!enlist(`a`b!4 5;`a`b!1 2)
"(,`val)!,+`a`b!(4 1;5 2)"
/no longer a table, now a list of dictionaries
q)-3!flip(1#`val)!enlist(`a`b!4 5;`a`b!1 2)
"+(,`val)!,(`a`b!4 5;`a`b!1 2)"
/extracting the column gives an "un-promoted" list of dictionaries
q)-3!exec val from flip(1#`val)!enlist(`a`b!4 5;`a`b!1 2)
"(`a`b!4 5;`a`b!1 2)"
/even though there are two of them and they both have type 99h, it is not a table
q)count exec val from flip(1#`val)!enlist(`a`b!4 5;`a`b!1 2)
2
q)type each exec val from flip(1#`val)!enlist(`a`b!4 5;`a`b!1 2)
99 99h
q)type exec val from flip(1#`val)!enlist(`a`b!4 5;`a`b!1 2)
0h

/so it is not comparable to something that has the promotion, even though the terminal makes them appear the same
q)((`a`b!4 5;`a`b!1 2))~exec val from flip(1#`val)!enlist(`a`b!4 5;`a`b!1 2)
0b
q)(`a`b!4 5;`a`b!1 2)
a b
---
4 5
1 2
q)exec val from flip(1#`val)!enlist(`a`b!4 5;`a`b!1 2)
a b
---
4 5
1 2

你的情况是一样的,但对于一个字典而不是两个,但我认为两个字典更容易看到。

于 2021-02-20T19:27:10.787 回答