因为 ccys 和 (-3 3) 的长度不同,所以您需要每个 left 和 each 都将带有 # 的 3 和 -3 应用于 ccys 中的每个字符串,而不是 ccys 本身。
// each left will apply -3 & 3 # to the entire ccys list
q)-3 3#:ccys
"CADUSD" "NZDUSD" "USDAUD"
"CADUSD" "NZDUSD" "USDAUD"
// each both will then apply the -3 & 3 # to each nested string
q)(-3,3)#':ccys
"USD" "USD" "AUD"
"CAD" "NZD" "USD"
// flip then transposes the 2 by 3 matrix of strings
// to a 3 by 2 matrix of strings
q)flip (-3,3)#':ccys
"USD" "CAD"
"USD" "NZD"
"AUD" "USD"
// this each right sv (scalar from vector) will merge each
// ccy into a currency pair. sv basically combines a list of strings,
// seperated by the left argument which in this case is nothing / ""
"" sv/:
// I would more commonly use raze each for this part:
q)raze each flip -3 3#':ccys
"USDCAD"
"USDNZD"
"AUDUSD"
至于更简单的方法,由于字符串的长度都相同,并且您只想交换第一个和最后 3 个字符,您可以深度索引来实现这一点:
q)ccys[;3 4 5 0 1 2]
"USDCAD"
"USDNZD"
"AUDUSD"