Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Input and Output

The embedding application supplies the library’s input and output callbacks. The CLI connects them to standard input and standard output. These operations are Functions, with normal argument evaluation.

FunctionArgumentsResult
print(value)One string, integer, float, or booleanNo value
read_line()NoneString or none

print

Formats a primitive value and sends its text to the output callback once. Strings are sent as their contents; booleans use true and false. The CLI adds a newline after each call. An embedding application’s callback may choose different output behavior.

print("Hello, DETLEF!")
print(42)
print(true)

There are no direct overloads for records, arrays, or none. Convert them explicitly with to_string, or construct a message with format:

print(to_string(array_of(1, 2, 3))) / [1,2,3]
print(to_string(none)) / null

The operation produces no value, so it cannot be used where a Function expects an argument value. See expressions without values.

read_line

Calls the input callback once. A supplied line becomes a string, with one trailing LF or CRLF removed. Other whitespace is preserved. End of input returns none; a blank line returns "". Input callback errors propagate as runtime errors. The CLI waits for input from its standard input stream, which can also be redirected from a file or a pipe.

print("What is your name?")
declare(name, optional(string), read_line())
if(is_none(name), {
    print("Input ended.")
}, {
    print(format("Hello, {name}!"))
})

Check for end of input with is_none, or provide a lazy fallback with or_else. Do not use an empty string as the end-of-input test. See absence values for the underlying type rules.