Re: Entering,Saving,and Analysis /Fitting X Y Data on the Prime Message #3 Posted by Han on 25 Oct 2013, 10:21 a.m., in response to message #2 by Eddie W. Shore
Quote:
Custom names are allowed. Any matrix with a name other than M0-M9 will appear under User Variables (accessed by the Vars key).
Using custom names for matrices in programs must be local and initialized.
To clarify Eddie's post:
EXPORT MYPROG()
BEGIN
LOCAL mymatrix=[[0]]; // initializes a real matrix;
mymatrix(50,50):=0; // sets the size; completely optional because matrices can be expanded dynamically
... code ...
END;
Matrices can be global variables, though. If you already created a matrix named MYMATRIX, then it can be used in your program without any variable delcaration. If MYMATRIX does not exist, then the program editor will complain with a Syntax Error -- you can then just exit the program editor and create a dummy MYMATRIX and this will fix the syntax error. Lastly, one may also have MYPROG() create a global variable as well (both visible and invisible).
EXPORT MYMATRIX; // export creates a global variable named MYMATRIX; initially value is 0
initMyProg; // create a flag; initially set to 0 (note lack of EXPORT)
EXPORT MYPROG()
BEGIN
if (initMyProg == 0) then
MYMATRIX:=[[0]]; // initializes the variable to 1x1 real matrix
initMyProg:=1;
end;
... more code ...
END;
Anytime a program file is edited (or even just viewed) it will get recompiled. So the flag initMyProg will determine whether or not to re-initialize the MYMATRIX or leave it intact to be reused by MYPROG().
Using EXPORT makes a global variable visible to the user, whereas leaving it out means the variable (while still global) is not visible to the user. Since we don't want users to be tinkering with the flag -- it should only be visible to the MYPROG() program -- then we do not export it.
|