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
Cui bono?
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
Cui bono?
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
Cui bono?
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
Cui bono?
Find all posts by this user
Quote this message in a reply
08-15-2021, 12:27 AM (This post was last modified: 08-15-2021 12:35 AM by jte.)
Post: #9
RE: Global Variables?
(04-03-2017 02:10 AM)Joe Horn Wrote:  
A hopefully-complete list of Prime's reserved variables can be found HERE.

A nice & useful list!

I did notice that descriptions are missing for a bunch of the Graph 3D app variables.

Descriptions for those whose GUI resides on page 3 of Graph 3D's Plot Setup view (BoxSides, BoxFrame, BoxAxes, BoxLines, BoxDots, and BoxScale) can be brought up by pressing Help after selecting one of them (BoxSides, say) from the Vars / App / Graph 3D / Plot choices. The "Box..." settings have to do with a virtual "box" that surrounds the plotted functions. Some of these may be understood quickly by interacting with a Graph 3D plot view with only one enabled at a time (going to page 3 of Graph 3D's Plot setup view, setting all but one to "None" / unchecked).

Similarly for those whose GUI resides on page 2 of Graph 3D's Plot Setup view (GridX, GridY, Surface, and KeyAxes). The KeyAxes is the little RGB XYZ axes display resident (when enabled) in the top left of Graph3D's Plot view.

... and, again, similarly for those whose GUI resides on page 4 of Graph 3D's Plot Setup view (BoxScale, PoseXaxis, PoseYaxis, PoseZaxis, and PoseTurn). The Pose... variables have to do with the orientation of the plot (transformation from the abstract XYZ space of the function surface plot to the XY coordinates of the screen). The user-facing description is intended to be a rotation around a vector (a turn of PoseTurn around the vector [PoseXaxis, PoseYaxis, PoseZaxis] if the XY plane of the abstract XYZ coordinates is aligned with the XY screen plane of the calculator).

Zmin, Zmax, and Ztick are direct analogues of Xmin, Xmax, and Xtick. (Or Ymin, Ymax, and Ytick.) Zmin and Zmax control the volume being plotted (which interval of Z the plot is for) while Ztick controls plot decorations (dots and lines).

Zzoom is similar to Xzoom and Yzoom: Zzoom controls the amount of zooming done along the Z dimension when a zoom is done in a Graph 3D Plot view.

(I started typing in descriptions of them just now, before realizing that there should be some online Help for them.)

FZ0-FZ9 are direct analogues of F0-F9 (from Function): these are the symbolic definitions of the functions considered for plotting. (Plotted if checked.)

(Z0-Z9 are not used in Graph 3D as they were already reserved for complex variables.)

I also noticed PPL variables are missing for some of the controls present in Graph 3D's Plot Setup view and that some of the Help has formatting issues. Sad Some of the variables in Graph 3D could be better understood / communicated with a diagram or two.
Find all posts by this user
Quote this message in a reply
08-15-2021, 12:49 AM
Post: #10
RE: Global Variables?
(08-15-2021 12:27 AM)jte Wrote:  
(04-03-2017 02:10 AM)Joe Horn Wrote:  A hopefully-complete list of Prime's reserved variables can be found HERE.
A nice & useful list!
I did notice that descriptions are missing for a bunch of the Graph 3D app variables. ...

Yikes! I created that list out of necessity, before the reserved variables were included in the built-in Help system. My list is now very out of date, and has been obsoleted by the Help system. I'll delete it as soon as I get access to my FTP server. Thanks for bringing it to my attention. Time flies when you're having fun! Smile

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
08-15-2021, 01:22 AM
Post: #11
RE: Global Variables?
(08-15-2021 12:49 AM)Joe Horn Wrote:  
(08-15-2021 12:27 AM)jte Wrote:  A nice & useful list!
I did notice that descriptions are missing for a bunch of the Graph 3D app variables. ...

Yikes! I created that list out of necessity, before the reserved variables were included in the built-in Help system. My list is now very out of date, and has been obsoleted by the Help system. I'll delete it as soon as I get access to my FTP server. Thanks for bringing it to my attention. Time flies when you're having fun! Smile

Oh! I like that it is a big list all in one place. I wasn't suggesting deletion or anything like that.

By "obsoleted", I'm guessing you mean the Catalog in Vars — that it is a comprehensive list and that descriptions of the variables included there can be obtained via the Help key. (Am I right?)

Perhaps a possible improvement to the help system is to have the particular variable automatically highlighted in the brought-up help (after pressing Help while in Catalog or in an editor) and have the brought-up help automatically scrolled to show the highlighted word. Some syntax colouring (to, e.g., call out names reserved by the system) when editing a PPL program might be useful for beginners.
Find all posts by this user
Quote this message in a reply
08-15-2021, 03:57 AM
Post: #12
RE: Global Variables?
(08-15-2021 01:22 AM)jte Wrote:  By "obsoleted", I'm guessing you mean the Catalog in Vars — that it is a comprehensive list and that descriptions of the variables included there can be obtained via the Help key. (Am I right?)

Exactly right. Kudos to HP for adding that feature.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
08-18-2021, 04:37 AM (This post was last modified: 08-18-2021 04:41 AM by cahlucas.)
Post: #13
RE: Global Variables?
(04-03-2017 04:39 PM)toml_12953 Wrote:  
(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

Dear Tom,
Try this code (it works on my G2):
Code:

BEGIN
LOCAL R;
R:=MAKEMAT(1,100):
END;
For all code that follows, the variable R will be global.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
08-18-2021, 09:55 AM
Post: #14
RE: Global Variables?
(08-18-2021 04:37 AM)cahlucas Wrote:  
(04-03-2017 04:39 PM)toml_12953 Wrote:  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

Dear Tom,
Try this code (it works on my G2):
Code:

BEGIN
LOCAL R;
R:=MAKEMAT(1,100):
END;
For all code that follows, the variable R will be global.

Strange... I get a SYNTAX ERROR at the first LOCAL.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
08-19-2021, 04:50 AM (This post was last modified: 08-19-2021 04:51 AM by cahlucas.)
Post: #15
RE: Global Variables?
(08-18-2021 09:55 AM)toml_12953 Wrote:  
(08-18-2021 04:37 AM)cahlucas Wrote:  Dear Tom,
Try this code (it works on my G2):
Code:

BEGIN
LOCAL R;
R:=MAKEMAT(1,100):
END;
For all code that follows, the variable R will be global.

Strange... I get a SYNTAX ERROR at the first LOCAL.

Dear Tom,
That's strange... Did you enter the program exactly as I did? The LOCAL statement must be within the BEGIN and END; words, and terminated with a ;. What can also matter is whether you use a G1 or a G2. Another hint: put the following on the first line of your program: # pragma mode(separator(.,;) integer(h32)) (first a period, then a comma, and finally a semicolon). I hope it works now. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
08-19-2021, 08:57 AM (This post was last modified: 08-19-2021 09:08 AM by toml_12953.)
Post: #16
RE: Global Variables?
(08-19-2021 04:50 AM)cahlucas Wrote:  
(08-18-2021 09:55 AM)toml_12953 Wrote:  Strange... I get a SYNTAX ERROR at the first LOCAL.

Dear Tom,
That's strange... Did you enter the program exactly as I did? The LOCAL statement must be within the BEGIN and END; words, and terminated with a ;. What can also matter is whether you use a G1 or a G2. Another hint: put the following on the first line of your program: # pragma mode(separator(.,Wink integer(h32)) (first a period, then a comma, and finally a semicolon). I hope it works now. Sincerely, Karel.

Yes, I entered it exactly by copying and pasting the code onto my G2. I'll try the pragma ... OK, I just tried the pragma and still get a syntax error at the same place. Here's what I have:
Code:
#pragma mode(separator(.,;) integer(h32))
BEGIN
 LOCAL R;
 R:=MAKEMAT(1,100);
END;
EXPORT test()
  PRINT(R(10));
END;

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
08-19-2021, 03:38 PM
Post: #17
RE: Global Variables?
(08-19-2021 08:57 AM)toml_12953 Wrote:  
(08-19-2021 04:50 AM)cahlucas Wrote:  Dear Tom,
That's strange... Did you enter the program exactly as I did? The LOCAL statement must be within the BEGIN and END; words, and terminated with a ;. What can also matter is whether you use a G1 or a G2. Another hint: put the following on the first line of your program: # pragma mode(separator(.,Wink integer(h32)) (first a period, then a comma, and finally a semicolon). I hope it works now. Sincerely, Karel.

Yes, I entered it exactly by copying and pasting the code onto my G2. I'll try the pragma ... OK, I just tried the pragma and still get a syntax error at the same place. Here's what I have:
Code:
#pragma mode(separator(.,;) integer(h32))
BEGIN
 LOCAL R;
 R:=MAKEMAT(1,100);
END;
EXPORT test()
  PRINT(R(10));
END;
There is sometimes an issue with the spaces in the pasted code. Remove and replace
the spaces on the calculator both before and after LOCAL. Hopefully that fixes it but other errors might then be apparent further down.
Find all posts by this user
Quote this message in a reply
08-20-2021, 04:04 PM (This post was last modified: 08-20-2021 04:05 PM by cahlucas.)
Post: #18
RE: Global Variables?
(08-19-2021 08:57 AM)toml_12953 Wrote:  
Code:

#pragma mode(separator(.,;) integer(h32))

There must also be a space between # and pragma. In my reply from Thursday, I stated it correctly.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
08-20-2021, 06:26 PM
Post: #19
RE: Global Variables?
(08-20-2021 04:04 PM)cahlucas Wrote:  
(08-19-2021 08:57 AM)toml_12953 Wrote:  
Code:

#pragma mode(separator(.,;) integer(h32))

There must also be a space between # and pragma. In my reply from Thursday, I stated it correctly.

When I put a space between # and pragma, I get a syntax error at the beginning of the word mode.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
01-20-2023, 02:46 AM
Post: #20
RE: Global Variables?
(08-19-2021 03:38 PM)Stevetuc Wrote:  
There is sometimes an issue with the spaces in the pasted code. Remove and replace
the spaces on the calculator both before and after LOCAL. Hopefully that fixes it but other errors might then be apparent further down.

As I’ve just mentioned (https://www.hpmuseum.org/forum/thread-99...#pid168514), a small change has been made to the HP Prime language parser that should help with this (I filed a ticket on this issue on the bug tracker I’ve set up; that ticket has been addressed) — for the parser to treat non-breaking space (U+00A0) as space itself (U+0020) is. This should make code sharing a little more convenient / less likely to introduce confusion.

(If anyone reading this would like an account on the bug tracker I’ve set up to help organize matters, just let me know by PM.)
Find all posts by this user
Quote this message in a reply
Post Reply 




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