Strings
This topic is meant to document strings in Pile
String Literals
String is a sequence of characters that are stored in memory. You can create them using double quotes ("
):
"This is my String"
Everytime you use string literals, the Pile interpreter will allocate the string in memory and push on the stack the corresponding metadata of the string back, that can later be used as a normal string.
String Manipulation
In Pile, strings are mutable, but not growable. If you are searching for a growable data structure, check arrays.
You can use sequence operations to manipulate strings in Pile.
Character Literals
Sometimes you don't need Pile's interpreter to allocate just a single character in memory just to be able to use it as text. You can avoid that by using character literals
To push a character on the stack, you use single quotes ('
). You do not need to close it with another '
.
# This is not a typo, you actually don't need to close it
'x
WARNING: Since character literals do not allocate strings, it just pushes the character code as an int
on the stack.