listSwap({list},i1,i2)
Swaps the i1 and i2 elements of list
(Credit to Bhuvanesh Bhatt for the general index and address expressions and programs, the
transpos() function, and lots of help with this tip!)
[3.17] Conditional tests on lists
Suppose you have two lists L1 and L2 and you want to know if they are identical, that is, each element
of each list matches the other. The conditional '=' operator does not return a single true or false result
when applied to the lists. Even so, this conditional expression will resolve to a single true or false result
when used as the argument to an If ... EndIf or when() function. For example, this works:
If L1=L2 then
(... code for L1 = L2 goes here ...)
else
(... code for L1 ≠ L2 goes here ...)
endif
The other conditional operators also work for lists, for example:
L1 > L2 evaluates to true if each L1 element is greater than the corresponding L2 element
L1 < L2 evaluates to true if each L1 element is less than the corresponding L2 element
L1 ≠ L2 evaluates to true if each L1 element is not equal to the corresponding L2 element
(Credit to Ray Kremer)
[3.18] Swap list elements
There is no built-in function to swap two list elements. This function exchanges the elements of list at
locations i1 and i2:
listswap(list,i1,i2)
func
©(list,i1,i2) list[i1]<->list[i2]
©Swap list elements
©29nov00/dburkett@infinet.com
local x
list[i1]→x
list[i2]→list[i1]
x→list[i2]
list
Endfunc
For example,
listswap({a,b,c,d},1,4)
returns {d,b,c,a}.
3 - 18