Post Reply 
Global vs Local behaviour
05-02-2015, 08:38 PM
Post: #2
RE: Global vs Local behaviour
I am fairly new to the HP Prime, but I think the correct way to declare a global variable so that it behaves as you expect is like this:

Code:

stg;
EXPORT str(stg)
BEGIN      
  return stg;
END;

If you change the value of the global variable used within the program the initial value will of course be lost (replaced):

Code:

stg;
EXPORT str(stg)
BEGIN      
  stg := 32;
  return stg;
END;

From my testing it would seem that the first place a variable is defined is where it's scope is assigned. Therefore if you define the variable as global even if you define the variable again inside of the BEGIN/END it remains a global and not a local variable, which could be confusing. Having the editor check to see if a variable has already been defined would be nice, but a little design effort can also avoid these types of problems.

Code:

stg;
EXPORT str(stg)
BEGIN 
  stg;     
  return stg;
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Global vs Local behaviour - DrD - 05-02-2015, 03:24 PM
RE: Global vs Local behaviour - kharpster - 05-02-2015 08:38 PM
RE: Global vs Local behaviour - DrD - 05-02-2015, 09:56 PM
RE: Global vs Local behaviour - kharpster - 05-02-2015, 10:29 PM
RE: Global vs Local behaviour - DrD - 05-03-2015, 02:18 AM
RE: Global vs Local behaviour - kharpster - 05-03-2015, 08:33 PM
RE: Global vs Local behaviour - DrD - 05-04-2015, 11:34 AM
RE: Global vs Local behaviour - DrD - 05-04-2015, 01:47 PM
RE: Global vs Local behaviour - leprechaun - 05-04-2015, 05:47 PM



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