Formulas for Lists
When you have a list, you can apply some formulas that are specific to working with lists. Here are some:
len()
You can know the number of elements a list has by using the len
operator.
Syntax: len( List )
cat()
Also, you can join two lists (as long as they have the same type) by using the cat
formula:
(
cat
is an abbreviation ofconcatenate
).
Syntax: cat( List, List )
Alternative Syntax: cat( Item, List )
You can also use this formula to push an element to the end of a list, resulting in a new list:
In Decipad, every operation returns a new value. Here,
cat
returns a new list and leaves the arguments untouched.
Or add an element to the beginning of a list:
first()
If you have a list and want to extract the first element, you can use the first
formula:
Syntax: first( List )
last()
Conversely, if you want to extract the last element of a list, you can use the last
formula:
Syntax: last( List )
sort()
You can generate a new list that contains all the elements in the source list sorted:
Syntax: sort( List )
unique()
You can generate a new list that contains all the unique elements in the source list sorted:
Syntax: unique( List )
reverse()
You can generate a new list that contains all the elements in the source list in reverse order:
Syntax: reverse( List )