Numbers, Atoms, Strings, and More
Xlerb’s datatypes are those of the BEAM. Unlike Forth which is basically untyped, and a big bag of binary data interpreted at runtime (i.e, taking a number to be a pointer, a boolean, an integer, etc), Xlerb supports the full suite of Erlang terms, with syntax familiar to Elixir folks:
We’ve seen how we can push numbers as literals:
xlerb[0]> 1 2 3
xlerb[3]> 1 2 3
We also have atoms, which are efficiently interned symbols, useful for parameters, tagging what a mesage is:
xlerb[3]> :atom :ok
xlerb[5]> .s
:ok
:atom
3
2
1
Booleans:
xlerb[5]> true false
xlerb[6]> =
xlerb[5]> .
false
xlerb[4]>
And string literals!:
xlerb[4]> "hello, xlerb!"
xlerb[5]> write
"hello, xlerb!"
xlerb[4]>
I don’t know what data types you’ll end up using most, since I’ve only just finished the compiler, but if you’re writing ‘pure’ Xlerb code, this probably is enough.
However, given we’re on the BEAM, we need to deal with tuples, lists, and maps. Suffice to say these are (probably?) un-idiomatic in a stack-based language, but unavoidable if we’re interacting with Erlang/Elixir code.
There’s a special syntax for dealing with these objects in (I hope) a nice way, which we’ll cover when we talk about Xlerb’s BEAM function-calling integration.