Primitives
Rock actually support some essential primitives.
Boolean
The Bool
type
main: ->
true.print!
false.print!
Integer
The most stable integer is Int64
and should be used until the rest follows.
main: -> 0
Rock has an inference mechanism that automatically assign types to variables and primitives
Here the main
function is special and has a fixed signature (Int64)
so 0
is a Int64
You can learn more about Function signature
Float
main: ->
let x = 2.2
x.print!
Char
main: -> '*'.print!
String
Strings are immutable (like in most language)
main: -> ("Hello" + " World!").print!
You can index them to get a Char
second_char: -> "Hello"[1]
Strings are 0-indexed
Both Strings and Chars accept some escaped characters:
\\ \' \" \n \r \0
In the future there will be a distinction between native Str
and on-the-heap String
like in Rust
Array
There is very limited support for arrays, they are still in development.
main: ->
let a = [1, 2, 3]
a[2] = 4
a[2]