Builtins
This topic is meant to document builtins in Pile
Overview
A builtin is an operation that is built into Pile's interpreter. Generally they are more complex compared to the standard operations (like +, -, ?). Builtins can have various use cases and help the developer to create programs with basic features.
I/O
| Builtin | Description |
open | ( path -- file ) | Pops a path as a string and opens a the file located in it and pushes the corresponding file object. |
read | ( file -- xs ) | Pops a file object on the stack and reads until EOF and pushes the read content as a string. |
readline | ( file -- line ) | Pops a file object on the stack and reads until the end of the line and pushes the read line as a string. |
write | ( file xs -- ) | Pops a file object on the stack and writes the specified content xs as a string. |
Typing and conversion
| Builtin | Description |
tostring | Converts the last element on the stack to a string. |
tofloat | Converts the last element on the stack to a float. If the conversion fails, it pushes a nil value instead. |
toint | Converts the last element on the stack to a int. If the conversion fails, it pushes a nil value instead. |
typeof | Pops 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
| Builtin | Description |
exit | Halts the execution of the program and exits with the exit code at the top of the stack. |
Strings
| Builtin | Description |
chr | Pops the last item on the stack (an integer) and interprets it as a character and pushes the corresponding string on top of the stack. |
ord | Pops a string of size 1 on top of the stack and pushes the character code as int back on the stack. |
Sequences
| Builtin | Description |
len | Pops a sequence on the top of the stack and pushes its size back. |