Q Language - Lists
优质
小牛编辑
132浏览
2023-12-01
列表是q language的基本构建块,因此对列表的透彻理解非常重要。 列表只是原子(原子元素)和其他列表(一个或多个原子的组)的有序集合。
列表类型
general list其项目括在匹配的括号中,并用分号分隔它们。 例如 -
(9;8;7) or ("a"; "b"; "c") or (-10.0; 3.1415e; `abcd; "r")
如果列表包含相同类型的原子,则称为uniform list 。 否则,它被称为general list (混合类型)。
Count
我们可以通过计数获得列表中的项目数。
q)l1:(-10.0;3.1415e;`abcd;"r") /Assigning variable name to general list
q)count l1 /Calculating number of items in the list l1
4
简单列表的示例
q)h:(1h;2h;255h) /Simple Integer List
q)h
1 2 255h
q)f:(123.4567;9876.543;98.7) /Simple Floating Point List
q)f
123.4567 9876.543 98.7
q)b:(0b;1b;0b;1b;1b) /Simple Binary Lists
q)b
01011b
q)symbols:(`Life;`Is;`Beautiful) /Simple Symbols List
q)symbols
`Life`Is`Beautiful
q)chars:("h";"e";"l";"l";"o";" ";"w";"o";"r";"l";"d")
/Simple char lists and Strings.
q)chars
"hello world"
**Note − A simple list of char is called a string.
列表包含原子或列表。 To create a single item list ,我们使用 -
q)singleton:enlist 42
q)singleton
,42
To distinguish between an atom and the equivalent singleton ,请检查其类型的符号。
q)signum type 42
-1i
q)signum type enlist 42
1i