Atoms

Ki provides a handful of basic, "atomic" types.

Boolean

Booleans are represented by the bool type, and have two possible values: true and false.

Numbers

There are three major types of numbers:

  • integer
  • floating-point
  • decimal

The decimal type provides exact, arbitrary-precision values. These are also sometimes known as "bignums".

Integers

  • int: a signed integer number which will grow into any size (although when it exceeds the max bit width of your machine, it will become much slower)
  • s8: 8-bit signed integer number
  • s16: 16-bit signed integer number
  • s32: 32-bit signed integer number
  • s64: 64-bit signed integer number
  • uint: an unsigned integer number which will grow into any size (although when it exceeds the max bit width of your machine, it will become much slower)
  • u8: 8-bit unsigned integer number
  • u16: 16-bit unsigned integer number
  • u32: 32-bit unsigned integer number
  • u64: 64-bit unsigned integer number

Ki is a little more worried about integer overflow than most other languages; see here for an exposition.

Floating-Point Numbers

  • f32: 32-bit floating-point number
  • f64: 64-bit floating-point number

Arbitrary Precision Numbers

  • dec: an arbitrary-precision, exact number

Numeric Literals

fn main() {
    val a: 1       # int
    val b: 1u      # uint
    val c: 1u8     # u8
    val d: 1u16    # u16
    val e: 1u32    # u32
    val f: 1u64    # u64
    val g: 1s8     # s8
    val h: 1s16    # s16
    val i: 1s32    # s32
    val j: 1s64    # s64
    val k: 1.0     # dec
    val l: 1.0f32  # f32
    val m: 1.0f64  # f64
    val n: 1d      # dec
}

Runes

Characters are represented by the rune type. A rune represents a 32-bit Unicode value.

fn main() {
    val a: 'a'
}

Use

Declaring variables using atomic types is easy:

fn main() {
    val boolean: true
    val integer: 13
    val float: 13.3
    val decimal: 714891203497180912837401923847102938471093284743701.8d
    val r: 'C'

    echo("Hey look, it's an integer: {{number}}!")
    echo("Hey look, it's a float: {{float}}!")
    echo("Hey look, it's a boolean: {{boolean}}!")
    echo("Hey look, it's a decimal: {{decimal}}!")
    echo("Hey look, it's a rune: {{r}}!")
}