Post Reply 
Prime app variables
12-14-2013, 02:36 AM
Post: #8
RE: Prime app variables
(12-13-2013 09:44 PM)Bob Frazee Wrote:  I have a similar problem.
...
How do I allow all of these programs to share variables with out making them global? In a conventional programming language, I would pass them as parameters, ie WindChillEqn(DegF,Mph,wct,wcto,ft), but that procedure doesn't appear to work in this language. Any help would be appreciated.
rcf

Is DegF a variable which must keep its value for all programs? In other words, if IntroScreen changes DegF, then is InputScreen supposed to use this new value? Or keep its own DegF? If all these programs are supposed to use a single value for DegF, then it would make sense to use a global variable. Just don't export it (if you don't want anyone other than the programs you wrote to mess with the values).

I have not had any issues passing parameters from one program to the next. The big question is whether the values passed should remain in the scope of the program to which they are passed vs. being kept for all programs to use. In order to properly call a subprogram, though, make sure to declare it before the program making the call. For example:

Code:

EXPORT global1, global2; // visible global variables
global 3; // hidden global variable

// declare subprograms here
SUBPRG1(); 
SUBPRG2(); 

EXPORT MAIN()
BEGIN
  LOCAL a, b, c, list;
  a:=1; b:=2; c:=3;
  list:=SUBPRG1(a,b,c);
  a:=list(1); b:=list(2); c:=list(3);
  list:=SUBPRG2(a,b,c);
  a:=list(1); b:=list(2); c:=list(3);
END;

// note the export
// this program becomes visible and usable by users
EXPORT SUBPRG1(a,b,c) 
BEGIN
  a:=2*a; b:=4*b; c:=8*c;
  RETURN({a, b, a});
END;

// note the lack of export
// this can only be called by other programs in this source file
SUBPRG2(a,b,c) 
BEGIN
  a:=a/2; b:=b/4; c:=c/8;
  RETURN({a,b,c});
END;

In the example above, we use a, b, and c as dummy variables for both subprograms. They are local variables and are destroyed when each subprogram returns to the main routine. Notice that in MAIN() I have to do lots of book-keeping in order to avoid global variables. Moreover, my subprograms must return lists in order to return multiple values. With global variables, you just declare them at the top and every program within the source file can use those variables. Excluding EXPORT just prevents users from messing with them.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Prime app variables - Jonathan Cameron - 12-13-2013, 03:33 PM
RE: Prime app variables - Han - 12-13-2013, 04:02 PM
RE: Prime app variables - Jonathan Cameron - 12-13-2013, 05:27 PM
RE: Prime app variables - Han - 12-13-2013, 05:42 PM
RE: Prime app variables - Jonathan Cameron - 12-13-2013, 06:17 PM
RE: Prime app variables - Han - 12-13-2013, 07:28 PM
RE: Prime app variables - Bob Frazee - 12-13-2013, 09:44 PM
RE: Prime app variables - Han - 12-14-2013 02:36 AM
RE: Prime app variables - Bob Frazee - 12-14-2013, 03:19 PM
RE: Prime app variables - Han - 12-14-2013, 09:19 PM
RE: Prime app variables - Bob Frazee - 12-15-2013, 04:02 AM
RE: Prime app variables - Han - 12-15-2013, 04:37 AM
RE: Prime app variables - Bob Frazee - 12-16-2013, 12:40 AM



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