Post Reply 
PPL programming question; local variables
02-13-2014, 01:07 PM (This post was last modified: 02-13-2014 01:08 PM by Han.)
Post: #8
RE: PPL programming question; local variables
(02-13-2014 11:47 AM)CR Haeger Wrote:  
(02-13-2014 07:01 AM)eried Wrote:  I am not sure if Han recommends re-declaring local vars outside and as parameters with the same name. You can do what you tried to do using another names for the parameter.

Anyway in general terms, you should avoid global vars, and unnecessary function calls (if the function is a couple lines and it is called once, then it shouldn't be a function, but also 'very lengthy functions' aren't good anyway).

Thank you. Yes, I was wondering if re-declaring local vars as parameters is what prevents them from being passed to the subroutine ANG(). I was hoping to not have to have (a,b) as separate local variables but maybe I have to in this case.

Those are all good recommendations. I just wanted to clarify a few points. The only global variable is the routine FINDANG() -- i.e. only exported variables are considered global. Defining local variables outside a procedural block doesn't make them global (in the same sense as the built-in variables A through Z) but simply gives them "file scope" from the point of declaration to the end to the file. They are similar to variables in C/C++ declared outside of functions.

The point of ANG() was to merely demonstrate the use of local variables declared outside of a procedural block. There are only a few instances in which something like ANG() would be used. For example, the MAKEMAT() command has three parameters: an expression in terms of I and J, the number of rows, and the number of columns. The expression can be a simple IF THEN END statement. However, the structure of the language does not allow such a block as a parameter so that you must use a separate function for your expression.

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


Messages In This Thread
RE: PPL programming question; local variables - Han - 02-13-2014 01:07 PM



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