<< Click to Display Table of Contents >>
List functions:
Note that some of the functions assume that the lists are lists of strings.
Function name |
Description |
Examples |
[x]-index |
Index: picks out a single element (at integer x position). In contrast to R, this does not return a 1-element list containing the variable. If you need that, use for instance #m[3..3]. Returns: var |
#m[3]; //the third element |
[x1..x2]-index |
Index: picks out a range of elements. You may omit x1 or x2. Returns: list |
#m[3..5]; //the third to fifth elements #m[3..]; |
[x1, x2]-index |
For a nested list of lists, #m[3, 5] will return the same element as #m[3][5], so this is just a convenience to make a nested list accessible like a matrix. See more here. Returns: variable |
#m = ((1, 2), (3, 4)); |
[x1..y1, x2..y2]-index [x1..y1, x2]-index [x1, x2..y2]-index |
For a nested list of lists, #m[2..3, 2..4] will select the given 'rows" and "columns", corresponding to selecting a submatrix from a matrix. Beware that in general, #m[2..3, 2..4] is completely different from #m[2..3][2..4]. See more here. Returns: list |
// 1 2 3 |
append(x1, x2) append(x1, i, x2) |
Adds variable x2 as it is at the end of list x1. Note that if x2 is a list of for instance 3 items, only 1 element is added (the list itself). If you need to add the 3 elements individually, use extend().
If used with i argument, x2 is inserted at index i, instead of at the end. See also extend().
To prepend, use append(x1, 1, x2).
Returns: list |
#y = #x1.append(#x2); //or: append(#x1, #x2) |
contains(x1, x2) |
Checks if the list of strings x1 contains the string x2. Returns 1 if true, 0 otherwise. You may alternatively use "x2 in x1", see the last example. See also the count() and index() functions. The comparisons are case-insensitive. Returns: val |
%v = #x1.contains(%s); |
count(x1, x2) |
Counts the number of times the string x2 is present in the list of strings x1. See also the contains() and index() functions.
Note: to obtain the number of elements in a list, use the length() function. The comparisons are case-insensitive.
Returns: val |
%v = #x1.count(%s); //or: count(#x1, %s) |
data(x) |
Accepts a string of blank-separated values x and turns them into a list of values. This is handy for long sequences of blank-separated numbers, instead of manually setting the commas. Returns: list |
#m = data('1.0 2.0 1.5'); |
dates(x) |
Tries to convert each element of the list x to a date. Returns: list |
#y = dates(#x); |
except(x1, x2)
|
The except() function subtracts x2 from x1. You may alternatively use the operator -. Only works for lists of strings. See also intersect() and union(). See also extend().
Returns: list |
#y = #x1.except(#x2); //or: except(#x1, #x2) |
extend(x1, x2) extend(x1, i, x2) |
The arguments x1 and x2 must be lists. The function inserts the elements of list x2 one by one at the end of (or at position i in) the list x1. The resulting list may contain dublets.
For two lists x1 and x2, you may alternatively use the + operator. See also except() and append().
To pre-extend, use extend(x1, 1, x2).
Returns: list |
#y = #x1.extend(#x2); //or: extend(#x1, #x2) |
flatten(x) |
For at list x, the function returns a flattened version of the list. For instance, the list (1, (2, 3)) is transformed into a non-recursive list of non-list elements: (1, 2, 3).
Returns: list
|
#m1 = (1, (2, 3)); |
index(x1, x2) |
Returns the index of the first occurrence of the string x2 in the list of strings x1. Returns 0 if x2 is not found in x1. See also the count() and contains() functions. The comparisons are case-insensitive. Returns: value (integer) |
%i = #x1.index(%s); //or: index(#x1, %s) |
intersect(x1, x2)
|
The intersect() function finds the common elements of the two list of strings x1 and x2. The resulting list will not contain dublets. You may alternatively use the operator &&. Only works for lists of strings. See also except() and union(). Returns: list |
#y = #x1.intersect(#x2); //or: intersect(#x1, #x2) |
join(x1, x2) |
For a string x1 and a list of strings x2, the method concatenates the x2 elements with x1 as separator. See also path(). Returns: string |
#m = ('x1', 'x2', 'x3'); |
length(x) len(x) |
Returns the number of elements in the list x. You may use len() instead of length(). Returns: val |
%v = #x.length(); //or: length(#x). |
list(x1, x2, ...) |
Returns a list of the variables x1, x2, etc. The function is handy for lists with only 0 or 1 elements. See examples. Returns: list |
#m = (); //will fail #m = (1, 2); //easy |
lower(x) |
Returns string elements in the list x as lower-case. Returns: list |
#y = #x1.lower(); //or: lower(#x1) |
path(x) |
For a list of strings x, the method concatenates the x elements with '\' as separator. See also join(), pathparts(). Returns: string |
#m = ('x1', 'x2', 'x3'); |
pop(x1, i) pop(x1) |
Removes the element at position i in the list x1. Removes the last element if called with pop(x). Returns: list |
#y = #x1.pop(2); //or: pop(#x1, 2) |
preextend(x1, x2) |
Same as extend(x1, 1, x2), putting the elements of x2 in the first position of x1. |
#y = #x1.preextend(#x2); //insert at position 1 |
prefix(x1, x2) |
If x1 is a list of strings, each element has the string x2 prefixed (prepended) Returns: list |
#y = #x1.prefix(%s); //or: prefix(#x1, %s); |
prepend(x1, x2) |
Same as append(x1, 1, x2), putting x2 in the first position of x1. |
#y = #x1.prepend(#x2); //insert at position 1 |
sort(x) sort(x, 'natural') |
Returns a sorted list of strings, provided that x is a list of strings. Sorting is case-insensitive. When the 'natural' argument is used, strings containing numbers will sort naturally, for instance returning a8, a9, a10, instead of a10, a8, a9. Returns: list |
#y = #x.sort(); //or: sort(#x) |
remove(x1, x2) |
Removes any string x2 from the list of strings x1. See also the except() function. Returns: list |
#y = #x1.remove(%s); //or: remove(#x1, %s); #y = #x1 - %s; //also legal |
reverse(x) |
Reverses list items. Returns: list. |
#x = a, b, c; |
replace(x1, x2, x3) replaceinside(x1, x2, x3) replaceinside(x1, x2, x3, max) |
replace(): In the list of strings x1, if this string element is the same as x2, x3 is inserted instead.
replaceinside(): the string element has any occurences of x2 inside the string replaced with x3. The replacements may be limited via the max argument.
Returns: list |
#y = #x1.replace(%x2, %x3); //or: replace(#x1, %x2, %x3) |
strings(x) |
Tries to convert each element of the list x to a string Returns: list |
#y = strings(#x); |
suffix(x1, x2) |
If x1 is a list of strings, each element has the string x2 suffixed (appended) Returns: list |
#y = #x1.suffix(%s); //or: suffix(#x1, %s); |
t(x) |
For a nested list of lists x, the t() function returns the transpose, similar to transposing a matrix. Returns: list (of lists) |
#m = ((1, 2), (3, 4)); |
union(x1, x2)
|
The union() function finds the union of the two lists x1 and x2. Alternatively use the operator ||. The resulting list will not introduce dublets, in contrast to the similar + operator (simple concatenation). Only works for lists of strings. See also except() and intersect(). Returns: list |
#y = #x1.union(#x2); //or: union(#x1, #x2) |
unique(x) |
Retains only those elements of list x that are unique (list of strings only). Returns: list |
#y = #x1.unique(); //or: unique(#x1) |
upper(x) |
Returns string elements in the list x as upper-case. Returns: list |
#y = #x1.upper(); //or: upper(#x1) |
vals(x) |
Tries to convert each element of the list x to a value Returns: list |
#y = vals(#x); |
venn(x1, x2)
|
For two lists of strings, this function prints out lists corresponding to a Venn diagram.
That is, intersection and two differences. For instance, venn(#m1, #m2) corresponds to printing out the following:
•#m1 && #m2 •#m1 - #m2 •#m2 - #m1
See also intercept(), except() and union(). Returns: nothing. |
#m1 = a, b, c, d, e; //Results: |