Ink has number, string, boolean, null, and composite values. Here are a few basic examples. |
|
std := load('../vendor/std') log := std.log |
|
Numbers, which support arithmetic operations, and more advanced functions using built-in native functions. |
length := (0.5 + 2 * 3 / 4 - 5) + ~6 % 7 log(length) ` a negative literal ` temperature := ~5 log(temperature) year := pow(10, 3) * 2 + 20 log(year) |
Strings, which can be added together with |
name := 'ada' + ' ' + 'lovelace' log(name) name.0 := 'A' name.len(name) := '!' log(name) |
Boolean. |
authed := true log(authed) log(~authed) log(true | false) log(true & false) |
Null. |
exists := () log(exists) |
Composite values, which are used for lists and maps. |
primes := [2, 3, 5, 7] log(primes) menu := { apples: 1.00 oranges: 1.50 } log(menu) |
We can get the value of a type with |
log(type(0)) |
$ ink values.ink -9 -5 2020 ada lovelace Ada lovelace! true false true false () {0: 2, 1: 3, 2: 5, 3: 7} {apples: 1, oranges: 1.50000000} number |
Next example: IO.