Nil Data

Ad Astra has a concept of nil data, a special object that intentionally does not represent any value.

Similar concepts exist in many scripting languages such as JavaScript, Python, nd Lua. However, in Ad Astra, nil data is less severe. For example, script code cannot access a variable that does not exist and receive nil data. Instead, such access would result in a hard compile-time error. Additionally, most built-in APIs usually never accept nil data types as arguments.

One practical case where nil data may appear is when an exported Rust function returns Option<T> and this option is None. Such a possibility should be clear to the user because the editor displays the original Rust function signature via the LSP server.

To check if a value is not nil, you can use the built-in foo? operator.

// fn exported_function() -> Option<usize>
let foo = exported_function();

match foo? {
    true => dbg(foo + 10),
    false => dbg("The result is nil"),
}

To manually construct a nil data object, you can use an array constructor without arguments.

[]? == false;

In general, it is recommended to avoid using nil data in scripts to prevent possible "null-pointer" bugs, but this decision ultimately depends on the script's design.