Functions
fprint()
This is a function that takes in a file as the first input and a string as the second input, and writes that string to the file.
fn fprint(file f, str value)
print() and println()
These functions call fprint() and with the output file set to be stdout.
The difference between print() and println() is that println() appends a
newline at the end of the output.
fn print(str value) {
fprint(os.stdout, value)
}
fn println(str value) {
fprint(os.stdout, value <> "\n")
}
eprint() and eprintln()
These functions call fprint() and with the output file set to be stderr.
The difference between eprint() and eprintln() is that eprintln() appends
a newline at the end of the output. These functions are generally used for
print debugging.
fn eprint(str value) {
fprint(os.stderr, value)
}
fn eprintln(str value) {
fprint(os.stderr, value <> "\n")
}
assert()
This is a function that takes in a boolean as the first argument, and optionally a string as the second argument. If the boolean is false, it halts the program with an assertion error and a stacktrace, and the string as an error message.
fn assert(bool check, str message) -> ! {
if check {
false -> { panic("ERROR: {message}") }
_ -> {}
}
}
fn assert(bool check) -> ! {
if check {
false -> { panic("ERROR: Assertion failed") }
_ -> {}
}
}
Note that although this function panics, you do not need to call it with try.
panic()
This function takes in a string as an argument, and crashes the program whenever it is called, displaying the string passed in as an error message. If a function in your code uses panic(), it must have a ! in its return type, and must be called with the try keyword.
fn panic(str message) -> !
Type casting functions
There are functions to cast a value into a different type:
bool()error()int(),uint()rat()str()
If you define a type of your own, you need to define these functions for that
type if you'd like to be able to convert into them. This is especially
important for str(), as you need to define it in order to print the value out
using the print() and
eprint() functions above.
asm()
This function allows you to write inline assembly in NC. Keep in mind that while the rest of the language is memory-safe, there are no such guarantees for any assembly code you may write or import from libraries using this function.
asm("""
; Your assembly code here
""")