Post Reply 
Global Variables?
04-03-2017, 12:40 AM
Post: #1
Global Variables?
Is there a way to make global variables using uppercase letters?

I'd like to use N:=20;
outside a begin-end block.
I'd also like to be able to use
R:=makelist(0,100);

I get syntax errors for both.
N1:=20; and r:=makelist(0,100); both work. however.

Tom L

Tom L
I'm pining for the Fjords
Find all posts by this user
Quote this message in a reply
04-03-2017, 02:10 AM (This post was last modified: 04-03-2017 02:13 AM by Joe Horn.)
Post: #2
RE: Global Variables?
(04-03-2017 12:40 AM)toml_12953 Wrote:  Is there a way to make global variables using uppercase letters?

I'd like to use N:=20;
outside a begin-end block.
I'd also like to be able to use
R:=makelist(0,100);

I get syntax errors for both.
N1:=20; and r:=makelist(0,100); both work. however.

The permanently-existing, built-in variables are "reserved" by the system and always contain specific object types. For example, A-Z always exist as global variables, and always contain a real number, and cannot be purged. That's why you can't assign a list to 'R'.

The reason 'N1' and 'r' do work in your example above is because they are not reserved variables, so they can contain any object type, or nothing at all (after being purged). A hopefully-complete list of Prime's reserved variables can be found HERE.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
04-03-2017, 02:59 AM
Post: #3
RE: Global Variables?
(04-03-2017 02:10 AM)Joe Horn Wrote:  
(04-03-2017 12:40 AM)toml_12953 Wrote:  Is there a way to make global variables using uppercase letters?

I'd like to use N:=20;
outside a begin-end block.
I'd also like to be able to use
R:=makelist(0,100);

I get syntax errors for both.
N1:=20; and r:=makelist(0,100); both work. however.

The permanently-existing, built-in variables are "reserved" by the system and always contain specific object types. For example, A-Z always exist as global variables, and always contain a real number, and cannot be purged. That's why you can't assign a list to 'R'.

The reason 'N1' and 'r' do work in your example above is because they are not reserved variables, so they can contain any object type, or nothing at all (after being purged). A hopefully-complete list of Prime's reserved variables can be found HERE.

Thanks, Joe. I knew about that but also know you can create local variables as any type you want. I was hoping there was some way to create a variable local to the program but global to all the subprograms in the program.

Tom L

Tom L
I'm pining for the Fjords
Find all posts by this user
Quote this message in a reply
04-03-2017, 03:02 AM
Post: #4
RE: Global Variables?
(04-03-2017 02:59 AM)toml_12953 Wrote:  Thanks, Joe. I knew about that but also know you can create local variables as any type you want. I was hoping there was some way to create a variable local to the program but global to all the subprograms in the program.

Tom L

Just declare them at the top of your source file.

Code:

// these may be accessed by any program created after the declaration of these variables
myvar1:={1,2,3}; 
myvar2:="Hello world";
myvar3:=1.2345;

EXPORT MYPROG1()
BEGIN
  PRINT(myvar1);
END;

EXPORT MYPROG2()
BEGIN
  myvar3:=myvar3 + 2;
  PRINT(myvar3);
END;

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
04-03-2017, 10:11 AM (This post was last modified: 04-03-2017 10:12 AM by toml_12953.)
Post: #5
RE: Global Variables?
(04-03-2017 03:02 AM)Han Wrote:  
(04-03-2017 02:59 AM)toml_12953 Wrote:  Thanks, Joe. I knew about that but also know you can create local variables as any type you want. I was hoping there was some way to create a variable local to the program but global to all the subprograms in the program.

Tom L

Just declare them at the top of your source file.

Code:

// these may be accessed by any program created after the declaration of these variables
myvar1:={1,2,3}; 
myvar2:="Hello world";
myvar3:=1.2345;

EXPORT MYPROG1()
BEGIN
  PRINT(myvar1);
END;

EXPORT MYPROG2()
BEGIN
  myvar3:=myvar3 + 2;
  PRINT(myvar3);
END;

The point of my post was that that doesn't work with uppercase variables. Try this:

Code:
N:=100;
R:=MAKEMAT(0,100);
myvar1:={1,2,3}; 
myvar2:="Hello world";
myvar3:=1.2345;

EXPORT MYPROG1()
BEGIN
  PRINT(myvar1);
END;

EXPORT MYPROG2()
BEGIN
  myvar3:=myvar3 + 2;
  PRINT(myvar3);
END;

Tom L
I'm pining for the Fjords
Find all posts by this user
Quote this message in a reply
04-03-2017, 10:25 AM
Post: #6
RE: Global Variables?
(Second line in your code block):

R is a reserved variable for reals only.
Find all posts by this user
Quote this message in a reply
04-03-2017, 01:18 PM (This post was last modified: 04-03-2017 03:07 PM by compsystems.)
Post: #7
RE: Global Variables?
Even with correct data generates an error, I think because a reserved variable is global for all programs and not a specific one.

The compiler should say the cause of the problem, instead of just SYNTAX ERROR

PHP Code:
X:=100;
M1:=MAKEMAT(0,100);
export testUserAndAppVars()
begin
  
PRINT();


  
//USER VARS
  
:= 1B:=2;
  
:= 5.9;
  
L1 := {1,{2},"HELLO"};
  
M1 := [[1,2,3],[4,5,6]];
  
Z1 := 3+4*i;


  
// APP VARS
  
PRINT( "F(X) Function app user symbolic variables" );
  Function.
F1 := 'X^3-6*X^2+11*X-6'// OR F1 := 'X^3-6*X^2+11*X-6'; OR CAS("F1(X):=X^3-6*X^2+11*X-6"); or sto('X^3-6*X^2+11*X-6',F1);
  
F2 := 'X^2-3*X+2';
  
F0 := 'X^3-0*X^2+X';
  
CAS("F3(X):=X^3"); // usando CAS CMD
  
CAS("F4(X):=X^3-2");
  
sto('X+5',F5); // usando STO CMD

  
PRINT( "F1(X) = " + Function.F1 );
  PRINT( 
"F2(X) = " + Function.F2 );
  PRINT( 
"F3(X) = " + Function.F0 );
  PRINT( 
"" );


  PRINT( 
"V(X,Y) Advanced Graphing app user symbolic variables" );    
  
V1 := 'X^2+Y^2 = 10';
  
V2 := '2*X-3*Y = 6';
  
V3 := 'Y MOD X = 3';
  
Advanced_Graphing.V4 := Function.F1+'Y'// usando dot


  
PRINT( "V1(X,Y) = " Advanced_Graphing.V1 );
  PRINT( 
"V2(X,Y) = " Advanced_Graphing.V2 );
  PRINT( 
"V3(X,Y) = " Advanced_Graphing.V3 );
  PRINT( 
"" );


  PRINT( 
"{ X(T), Y(T) } PARAMETRIC app user symbolic variables" ); 
  
Y1 := 'SIN(4*T)';
  
X1 := 'SIN(6*T)';
  PRINT( 
"{ X1(T) = " Parametric.X1 ", Y1(T) = " Parametric.Y1 " }" );
  PRINT( 
"" );

  PRINT( 
"R(THETHA) POLAR app user symbolic variables" );
  
R1 := 'SIN(θ)';
  PRINT( 
"R(θ) = " Polar.R1 );
  PRINT( 
"" );

  PRINT( 
"EQ() SOLVE app user symbolic variables" );
  
E1 := 'X^2';
  
E2 := '2*X+3';
  PRINT( 
"{ E1(X) = " E1 ", E2(X) = " E2 " }" );
  PRINT( 
"END" );

  
//User Vars
  // {"A", "B", "X","L1","M1","Z1","F1","F2","F0","V1","V2","T"})

  //F(X) Function symbolic variables
  // { "F0","Function.F1","F1", "F2","F3","F4","F5","F6","F7","F8","F9" }

  // V(X,Y) Advanced Graphing symbolic variables 
  // { "V0","V1","V2","V3","V4","V5","V6","V7","V8","V9" }

  // { X(T), Y(T) } PARAMETRIC symbolic variables
  // { "X0","X1","X2","X3","X4","X5","X6","X7","X8","X9" }
  // { "Y0","Y1","Y2","Y3","Y4","Y5","Y6","Y7","Y8","Y9" } 

  //R(THETHA) POLAR symbolic variables
  // { "R0","R1","R2","R3","R4","R5","R6","R7","R8","R9" }


  
return "Done";
end
Find all posts by this user
Quote this message in a reply
04-03-2017, 04:39 PM
Post: #8
RE: Global Variables?
(04-03-2017 10:25 AM)DrD Wrote:  (Second line in your code block):

R is a reserved variable for reals only.

Yes, I know that but my question was - since R:=MAKEMAT(0,100); works for local variables, is there a way to make it local to the current program file but global to all the subprograms in that file. The answer as it turns out is "No"

Tom L

Tom L
I'm pining for the Fjords
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)