如何计算 K 中每个列表的长度?

How to count each list length in K?

在页面上 https://shakti.com/tutorial/ 我找到了解决方案,它是

#:'z / counts each list

通过在 q:

中切换到 k 模式,在 https://code.kx.com/v2/learn/startingkdb/language/ 中提到了相同的解决方案
q) #:'(1 2;"abc")            / equivalent k expression
2 3

为什么这个表达式#:'算数?

在页面 http://www.math.bas.bg/bantchev/place/k.html 他们提到:

: within |: is used to force the verb | to be interpreted as a monad, as by default ambiguities are resolved in favour of dyads

也在这里 http://web.archive.org/web/20050504070651/http://www.kx.com/technical/documents/kreflite.pdf 注意到相同的内容:

Note that whenever Each is applied to the monad of a primitive verb, as in !:' for Enumerate-Each, the monadic case must be made explicit by modifying the verb with colon. The dyadic case is assumed if no modifier is present.

这是有道理的:

/ # want's to act as dyadic verb
  #' (1 2; "abc")
#'[(1 2;"abc")]

/ make use of dyadic # behavior
  5 6 #' (1 2; "abc")
(1 2 1 2 1;"abcabc")

/ monadic case
  #:' (1 2; "abc")
2 3