[3.10] Appending is faster than augment() for adding elements to lists; seq() is even faster
Frank Westlake says that:
When working with lists it can be much quicker to append rather than to augment new values. The
append operation continues at the same rate, regardless of the size of the list, but the augment
operation continues to decrease speed as the list grows in size. For example:
apnd()
prgm
local i,list
{}→list
for i,1,100
disp i
i→list[i]
endfor
disp list
endprgm
is much quicker than
agmnt()
prgm
local i,list
{}→list
for i,1,100
disp i
augment(list,{i})→list
endfor
disp list
endprgm
The apnd() program executes in about 9.8 seconds, and the agmnt() program finishes in about 17.9
seconds.
However, if your list element expression is simple enough to be used in the seq() function, this is much
faster than either augment() or appending. This function:
seq(i,i,1,100)→list
executes in less than 2 seconds.
(Credit to Frank Westlake)
[3.11] Store anything in a matrix
Matrices can hold more than just numbers. In fact, they can hold expressions, strings and variables. In
most programs, this makes matrices a better data structure than a data variable, since you cannot
directly write to the items in a data variable.
This tip from an anonymous poster: Lists can be saved in a matrix as strings. Use this to store the list:
string(list)→M[j,k]
where list is the list and M is the matrix. Use this to extract the list:
3 - 6