Builtins

This topic is meant to document builtins in Pile

What is a builtin?

A builtin is an operation that is built into Pile's interpreter. Builtins can have various use cases and help the developer to create programs with basic features.

I/O

BuiltinDescription
printPrints the last element on the stack to stdout.
printlnPrints the last element on the stack to stdout with a newline character at the end.
eprintPrints the last element on the stack to stderr.
eprintlnPrints the last element on the stack to stderr with a newline character at the end.
inputReads input from stdin until EOF and pushes the input on top of the stack.
inputlnReads only a line from stdin and pushes the input on top of the stack.

Typing and conversion

BuiltinDescription
tostringConverts the last element on the stack to a string.
tofloatConverts the last element on the stack to a float. If the conversion fails, it pushes a nil value instead.
tointConverts the last element on the stack to a int. If the conversion fails, it pushes a nil value instead.
typeofPops the last item on the stack and pushes the name of the respective type of the item in question as a string.

Environment and System

BuiltinDescription
exitHalts the execution of the program and exits with the exit code at the top of the stack.

Strings

BuiltinDescription
chrPops the last item on the stack (an integer) and interprets it as a character and pushes the corresponding string on top of the stack.
ordPops a string of size 1 on top of the stack and pushes the character code as int back on the stack.

Sequences

BuiltinDescription
lenPops a sequence on the top of the stack and pushes its size back.