簡體   English   中英

表轉換,表作為字典列表

[英]Table transformation, table as list of dicts

請通過以下路徑幫助我進行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相同的 object ,但事實並非如此。 出於某種原因,只有[;]t2獲取t1

那么第 2 行和第 5 行發生了什么(以及為什么)?


UPD為什么enlist如此富有成效? 它對每個元素進行登記,翻轉整個 object

-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)

我認為這里發生的事情是,當它成為表的列時,將(符合)字典列表的特殊提升到表本質上是“撤消”的。 它可以追溯到字典列表,就好像它們不符合標准一樣,盡管終端仍然會誤導地顯示它,就好像它是一個表格一樣。 要看到這一點,請考慮以下示例:

/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

你的情況是一樣的,但對於一個字典而不是兩個,但我認為兩個字典更容易看到。

暫無
暫無

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

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