Next: , Previous: , Up: Top  


4 Noun

The basic data types of the k9 language are booleans, numbers (integer and float), text (characters and enumerated/name) and temporal (date and time). It is common to have functions operate on multiple data types.

In additional to the basic data types, data can be put into lists (uniform, i.e., all elements of the same type, and non-uniform), dictionaries (key-value pairs), and tables (transposed/flipped dictionaries). Dictionaries and tables will be covered in anohter chapter.

Here are some examples of each of these types (note that 0N is a null integer and 0n a null float).

type              
bool 011b
int  0N 0 2 3
flt  0n 0 2 3.4   
char " ab"        
name ``ab         
uuid

date 2024.01.01
time 12:34:56.123456789

Data types can be determined by using the @ function on values or lists of values. In the case of non-uniform lists @ returns the type of the list `L but the function can be modified to evaluate the type of each element in the list using @'.

 @1            / integer atom
`i
 @1 2 3        / integer list
`I
 @12:34:56.789 / time atom
 @(3;3.1;"b";`a;12:01:02.123;2020.04.05) / mixed list
`L
 @'(3;3.1;"b";`a;12:01:02.123;2020.04.05)
`i`f`c`n`t`d

4.1 Atom Types

This section lists all the different types available. Generally lower case specifies atoms and upper case as lists.

nametypeexamplenote
bboolean1b
ccharacter“a”
ddate2020.06.14
efloat3.1
ffloat3.1f
gint2g1 byte unsigned
hint2h2 byte unsigned
iint24 byte unsigned
jint2j8 byte signed
nname`abc8 char max
stime12:34:56second
Sdatetime2020.06.15T12:34:56second
ttime12:34:56.123millisecond
Tdatetime2020.06.15T12:34:56.123millisecond
utime12:34:56.123456microsecond
Udatetime2020.06.15T12:34:56.123456microsecond
vtime12:34:56.123456789nanosecond
Vdatetime2020.06.15T12:34:56.123456789nanosecond

4.2 bool ⇒ Boolean b

Booleans have two possible values 0 and 1 and have a ’b’ to avoid confusion with integers, eg. 0b or 1b.

 0b
0b
 1b
1b
 10101010b
10101010b

4.2.1 boolean logic

k9 implements logic operations in the usual way.

 x:0101b;y:0011b

[[x:x;y:y]AND:x&y;OR:x|y;NAND:~x&y;NOR:~x|y;XOR:~x=y;XNOR:x=y]
x y|AND OR NAND NOR XOR XNOR
- -|--- -- ---- --- --- ----
0 0|  0  0    1   1   0    1
1 0|  0  1    1   0   1    0
0 1|  0  1    1   0   1    0
1 1|  1  1    0   0   0    1

4.3 Numeric Data

Numbers can be stored as integers and floats.

4.3.1 int ⇒ Integer g, h, i, j

Integers can be stored in four different ways which correspond 1, 2, 4, and 8 bytes. The first three are unsigned and the last (j) is signed. Positive numbers default to i and negative and very large numbers default to j. One can specify a non-default type by adding one of the four letters immediately following the number.

 @37    / will default to i
`i
 @-37   / negative so will default to j
`j

 @37g   / cast as g, one byte unsigned
`g

b:{-1+*/x#256}
 `g b[1]
255g
 `h b[2]
65535h
 `i b[4]
4294967295
 `j b[7]
72057594037927935

4.3.2 flt ⇒ Float e, f

Float

 3.1
3.1
 3.1+1.2
4.3
 3.1-1.1   
2.
 @3.1-1.1
`e
 @3.1
`e
 a:3.1;
 @a
`e
 @1%3
`f

4.4 Text Data

Text data come in characters, lists of characters (aka strings) and enumerated types. Enumerated types are displayed as text but stored internally as integers.

4.4.1 char ⇒ Character c

Characters are stored as their ANSI value and can be seen by conversion to integers. A string is a list of characters (including blanks).

 @"b"
`c
 @"bd"
`C 

4.4.2 name ⇒ Name n

A name is an enumerated type displayed as a text string but stored internally as an integer value.

 @`blue
`n
 @`blue`red
`N

4.5 Unique Identifier

TBD

4.5.1 uuid ⇒ Uuid

TBD

4.6 Temporal Data

Temporal data can be expressed as time, date, or a combined date and time.

4.6.1 time ⇒ Time s, t, u, v

Time has four types depending on the level of precision. The types are seconds (s), milliseconds (t), microseconds (u), and nanoseconds (v). The times are all stored internally as integers. The integers are the number of time units. For example 00:00:00.012 and 00:00:00.000000012 are both stored as 12 internally.

 @12:34:56.789             / time
`t
 .z.t                       / current time in GMT (Greenwich Mean Time)
17:32:57.995
 t: .z.t-17:30:00.000; t
00:03:59.986
 t
17:33:59.986
 `i 00:00:00.001            / numeric representation of 1ms
1
 `i 00:00:01.000            / numeric representation of 1s
1000
 `i 00:01:00.000            / numeric representation of 1m
60000
 `t 12345                   / convert number to milliseconds
00:00:12.345

4.6.2 date ⇒ Date d

Dates are in yyyy.mm.dd format. Dates are stored internally as integers with 0 corresponding to 2001.01.01.

 @2020.04.20               / date
`d
 .z.d                       / current date in GMT
2020.12.05
 `i .z.d                    / numeric representation of date
7278
 `i 2001.01.01              / zero date
0
 `d 0                       / zero date
2001.01.01

4.6.3 datetime ⇒ Datetime d

Dates and times can be combined into a single datetime element by combining a date, the letter T, and the time together without spaces. The datetime use the same lettering as the time precision but in uppercase. Datetimes are stored interally as integers. For example 2001.01.02T00:00:00.000 is stored as 86,400,000, the number of milliseconds in a day.

 @2020.04.20T12:34:56.789  / date and time
`d
 `T$"2020.04.20 12:34:56.789" / converting from string
2020.04.20T12:34:56.789

4.7 Extreme values

Data types can represent in-range, null, and out-of-range values.

typenullout of range
i0N0W
f0n0w
 0%0
0n
 1e500
0w

Next: , Previous: , Up: Top