Skip to main content

axiom

Every program has axiom, with no import. It holds printing, strings, turning a value into text, a program's resource files, and the bytes and utf types.

Printing​

MemberWhat it does
print(x)Prints x as text, with no line break after it: anything string(x) takes
println(x)Prints x as text and ends the line
println()Ends the line, or prints an empty one

What a program prints shows in IntelliJ's run window.

print("Ready")
println(", set, go")
println()
println("after an empty line")
Output
Ready, set, go

after an empty line

print and println take any value string(x) takes, so println(5) prints 5 and println(21.5) prints 21.5. A value that may be missing prints as its value, or as none when there's nothing there:

println(5)
println(21.5)

let comma: i32? = "a,b".find(",")
println(comma)
Output
5
21.5
1

Strings​

A string is text. Its length and its index count code points, so an accented letter or an emoji is one.

MemberWhat it does
s.lengthHow many code points s has
s[i]The code point at index i, as a utf, counting from 0
s.slice(start, end)The text from index start up to, but not including, end
s.contains(t)Whether t appears in s
s.startsWith(p), s.endsWith(x)Whether s begins with p, or ends with x
s.trim()s without the white space at either end
s.find(t)Where t first appears, as an i32?: nothing when it doesn't
s.split(separator)The pieces between each separator, as a string[]
a + ba and b joined
==, !=, <, <=, >, >=Compare two strings
let line = " motor A, 50 ".trim()
let first: utf = line[0]
let name = line.slice(0, 7)
let parts = line.split(", ")

println(name + " has " + string(line.length) + " letters")
println(line.startsWith("motor"))

if (let at? = line.find(",")) {
println("comma at ${at}")
}
Output
motor A has 11 letters
true
comma at 7

An index or a slice outside the string ends the run with a fault.

A value as text​

FormWhat it does
string(x)x as text: an integer, a float, a boolean, a utf, or a class with its own toString(). A float is its shortest decimal, so string(21.5) is "21.5"
x.toString()The same, written after the value
"count: ${n}"Puts n into the text where the ${…} is
i64("12345"), f64("1.5"), boolean("true")A number or a boolean from text written in the program
let n = 7
println("n is " + string(n))
println("n is " + n.toString())
println("n is ${n}")
println("ready: " + string(true))
println("half of 43 is " + string(21.5))

let big = i64("12345")
println(big + 1)
Output
n is 7
n is 7
n is 7
ready: true
half of 43 is 21.5
12346

A class gives itself a text form with a toString(), and then string(…) and ${…} use it:

class Point(let x: i32, let y: i32) {
let toString(): string = "(${x}, ${y})"
}

The forms that read text, such as i64, take text written in the program, and the build reads it as the program compiles.

Doesn't compile

Text and a number don't join with +. The build says to write string(5):

println("count: " + 5)

Resource files​

Resources.data(path) gives a program a file it ships, as bytes. Resource files says where the files go and how a path is written.

let greeting: bytes = Resources.data("greeting.txt")
println(string.fromUtf8(greeting))

With greeting.txt holding Hello, it prints:

Output
Hello

bytes and utf​

  • bytes is raw data, a u8[]: what Resources.data gives. data.size is how many bytes it holds, data[i] is one of them, and string.fromUtf8(data) reads them as text.
  • utf is one code point: what a string's index gives. string(c) makes it a one-letter string.
let data: bytes = Resources.data("greeting.txt")
println(data.size)
println(data[0])

With the same greeting.txt, it prints its size, then its first byte, the H:

Output
5
72