Expressions of lists
Comparaison operators applies to dynamic list also, array and dict.Binary operators allow to perform same operation on lists.
And list have a particular operator, in that will be studied in a further chapter.
Operators on lists (array, dict)
= < > <= >= <>
+ - [ ] in & | ^ |
compare two lists for values. concatenate two lists (doubloons may result)). remove from a list, element of a second one (but doubloons). indexing, slicing or splicing (see at array and dict). test if an element is in a list. intersection. union. complement of intersection. |
Example of "in": | if "a" in ("a", "b", "c") print "found" |
The intersection of two lists return the list of common elements. The union of two lists returns the sum of elements from the two lists. Elements that exists in both the two lists are added once. If one of the two lists previously contained an element twice, only the first occurence will be kept.
List expression is a powerful feature of Scriptol. You can test, for example, if a list is a part of another one:
Example of array intersection: | array
a = array(2,3,4) array b = array(1,2,3,4,5,6) if (a & b) = a) print "a is a part of b" else print "not in b" /if |
Displays: | > a is a part of b |
We have so replaced an algorithm by a simple conditional expression.
Exercises |
1) Merging two arrays. |