-
Notifications
You must be signed in to change notification settings - Fork 0
Lists
Lists are a very powerful kind of variable and can store any type of data. Creating a list is easy:
set myList to list()Creating a new list with elements is easy as well:
set myFruits to list("Apple", "Orange", "Banana")If you add an element to a list, it will be appended at the end of the list:
set myFruits to listAdd(myFruits, "Cherry")As you can see, all list functions are returning copies, so you have to store the result. For example this:
listAdd(myFruits, "Cherry")does not alter the variable myFruits! It just creates a copy which, in this case, is not assigned so the interpreter discards it.
A string in jask can be treated as an implizit list of characters, see the following example:
print(listGet("12345", 3))This will print the string "4".
Returns a new list containing the given elements. Please note that list() does not support named parameters.
Returns the size of the given list or number of characters in a list.
Adds the given element to a copy of the given list and returns the copy. If a string is passed as the first parameter, the element to add must be a string as well. In this case, a new string will be created with the element added at the end.
Returns the element at the given index in a list or a character in a string.
Returns the elements in the given range in a list or a substring in a string.
Sets an element at the given index to a copy of the given list and returns the copy. If a string is passed as the first parameter, the element to be set must be a string as well. In this case, a new string will be created with the given string replaced at the given index. Please notice: If the string element is longer than one character, following characters in the string will be overwritten.
Removes the element at the given index in a copy of the given list and returns the copy. If a string is passed as the first parameter, a copy of the string is returned with the charater at the provided index removed.
Creates a reversed copy of the given list or string and returns the copy.
Creates an expanded copy of the given list and returns the copy.