Sequence Operations
Learn how work with sequence structures in Pile.
What are sequences in Pile?
In Pile, there are 2 types of sequences:
Sequence operations work in both of the sequence types but they may have different behaviors.
All behaviors for each operation/sequence type are documented here.
Reference
Name | Operation | Description |
Index At | @ | Reads an element of a sequence from a specified index (starting from 0) |
Write At Index | ! | Writes a specified element into the sequence at a determined index (starting from 0) |
Usage
Usage for arrays
# Define array to be used and save it in a variable
array 1 2 3 end
let my_array
# Use @ to read at a specific index of the array
my_array 1 @ # Result: 2
# Use ! to change the element at the index
my_array 790 1 ! # Changed 2 to 790
Usage for strings
# Create string to be used and save it in a variable
"fello"
let my_string
# Use @ to read a character at a specific index of the array
# (the result is always a string of length 1)
my_string 2 @ # Result: "l"
# Use ! to replace the character at the index in the string
my_string 'h 2 ! # Now the string is "hello"