Appendix D: Code Bytes
This appendix contains some commonly used snippet examples in Calyxium; designed to be searched by that search bar up ↑ give it a try!
Under Construction
For loops
As you can see in Appendix A for
loops have been discontinued
and are no longer accessible. For those of you who are used to imperative programming this may seem like a shock;
how am I supposed to loop things? You may ask, well its pretty simple. You use the rec
keyword. Below is a template for
loop and how to use it.
let rec iterator(index, max) {
if index < max then {
print(index)
iterator(index + 1, max)
}
}
iterator(0, 9)
The following code will run print
10 times.
This is a very simple for
loop style function but they can get much more
complex giving you more control than the standard for
keyword from other languages.
Calling the iterator
function starts the loop and you pass in index 0 and the max loop value.
Passing in the values like this is similar to for i in range(start, end)
in Python.
While loops
You can do a similar thing for a while
loop with the following code.
let rec iterator() {
print("I'm a happy while loop!")
iterator()
}
iterator()