list Operators
The following operations can be used with list expressions:
-
insert: insertsexpression, atlist, {index}expressionat the specified index in the list, shifting up other list elements with higher indices -
remove: removes the element oflist, {index}listat the specified index and returns it, shifting down other list elements with higher indices -
push: appendsexpression, ontolistexpressiononto the end of list -
pop: removes the last element oflistlistand returns it -
prepend: prependsexpression, ontolistexpressiononto the start oflist -
unprepend: removes the first element oflistlistand returns it -
: returns the element of the list at offset expression. The expression index is zero based, as in C, such that 0 refers to the first element, 1 to the second, and so forth. If the offset expression is less than zero, or greater than the length of the list minus one (because the access is zero based), an error is triggered and the simulation is stopped.list, {expression} -
: sets an element of the list at offset expression to value. The offset index is again zero based. If the offset expression is less than zero or greater than the size of the list an error is triggered and the simulation is stopped. If the offset expression is equal to the size of the list, the list is extended by one element; the operation has the same effect as pushing a value on to the end.list, {expression, } =value -
sort: sortslist, withmethod-namelistusing the method specified withmethod-name.method-namemust be a method which takes two list elements (the keywords are unimportant) and compares them, returning a negative number if the first list element belongs before the second in the sorted list, a positive number if the second belongs before the first, and 0 if the two entries are equal. In most cases, this confusing sounding method returns a certain value associated with one argument minus the same value in the other.Unlike the perl sort operator,
sortoperates on the list it is given and does not return a copy of it. This means that the original list is modified during the sort operation. -
copylist: copies the entire list. Normally, assigning a list to a variable will not copy the list but instead will yield two variables pointing to the same list.list -
|: gives the length of a list. Lists are automatically converted to integers when use in mathematical expressions, but this construct can be used too force the conversion.list|
