Next: List, Previous: Adverbs, Up: k9: Manual
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 another chapter.
Here are some examples of each of these types (note that 0N is a null integer and 0n a null float).
Type char " ab" sym ``ab bool 011b int 2 3 4 float 2 3e4 fixed 2.0 3.4 locus -74::40.7 date 2001.02.03 time 12:34:56.789 datetime
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
This section lists all the different types available. Generally lower case specifies atoms and upper case as lists.
name | type | example | note |
b | boolean | 1b | |
c | character | “a” | |
d | date | 2020.06.14 | |
e | float | 3.1 | |
f | float | 3.1f | |
g | int | 2g | 1 byte unsigned |
h | int | 2h | 2 byte unsigned |
i | int | 2 | 4 byte unsigned |
j | int | 2j | 8 byte signed |
n | name | `abc | 8 char max |
s | time | 12:34:56 | second |
S | datetime | 2020.06.15T12:34:56 | second |
t | time | 12:34:56.123 | millisecond |
T | datetime | 2020.06.15T12:34:56.123 | millisecond |
u | time | 12:34:56.123456 | microsecond |
U | datetime | 2020.06.15T12:34:56.123456 | microsecond |
v | time | 12:34:56.123456789 | nanosecond |
V | datetime | 2020.06.15T12:34:56.123456789 | nanosecond |
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
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
Numbers can be stored as integers and floats.
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
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
Fixed TBD
2 3e4 2.000e+00 3.000e+04
Locus TBD
-74::40.7 4.07e+01
Text data come in characters, lists of characters (aka strings) and enumerated types. Enumerated types are displayed as text but stored internally as integers.
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
A symbol (sym) is an enumerated type displayed as a text string but stored internally as an integer value.
@`blue `n @`blue`red `N
Temporal data can be expressed as time, date, or a combined date and time.
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
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
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
Data types can represent in-range, null, and out-of-range values.
type | null | out of range |
i | 0N | 0W |
f | 0n | 0w |
0%0 0n 1e500 0w
Next: List, Previous: Adverbs, Up: k9: Manual