English 中文(简体)
Q Language - Lists
  • 时间:2024-12-22

Q Language - Lists


Previous Page Next Page  

Lists are the basic building blocks of q language, so a thorough understanding of psts is very important. A pst is simply an ordered collection of atoms (atomic elements) and other psts (group of one or more atoms).

Types of List

A general pst encloses its items within matching parentheses and separates them with semicolons. For example −

(9;8;7)   or   ("a"; "b"; "c")   or   (-10.0; 3.1415e; `abcd; "r")

If a pst comprises of atoms of same type, it is known as a uniform pst. Else, it is known as a general pst (mixed type).

Count

We can obtain the number of items in a pst through its count.

q)l1:(-10.0;3.1415e;`abcd;"r")    / Assigning variable name to general pst

q)count l1                        / Calculating number of items in the pst l1
4

Examples of simple List

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 psts and Strings.
q)chars
"hello world"

**Note − A simple pst of char is called a string.

A pst contains atoms or psts. To create a single item pst, we use −

q)singleton:enpst 42

q)singleton
,42

To distinguish between an atom and the equivalent singleton, examine the sign of their type.

q)signum type 42
-1i

q)signum type enpst 42
1i
Advertisements