|
Post by Carl Gundel on Feb 27, 2019 8:03:13 GMT -5
I'll look into this, but why are you passing globals as parameters? Maybe there is another way?
|
|
|
Post by Brandon Parker on Feb 27, 2019 8:30:52 GMT -5
I'm with Carl on this one....
What would be the point of a variable needing to be "passed" as an argument to a function/ subroutine when it is already freely available inside the function/ subroutine. Should Global variables be able to be passed in as arguments and the formal parameters of the function/ subroutine be named the same you would actually be creating a form of Variable "Ghosting" which is frowned upon due to the confusion it causes with which scope the variable you are working with has.
Just my opinion.....
{:0)
Brandon Parker
|
|
|
Post by tsh73 on Feb 27, 2019 8:40:42 GMT -5
well, the point is *exactly* to pass variable in a subroutine.
Having it under another name -as a sub/function argument. Supposedly it works with other variables Now if I happen to need to pass the thing happened to be global variable - why not? What am I to do? Create local copy and pass _that_? Why?
|
|
|
Post by Brandon Parker on Feb 27, 2019 9:57:15 GMT -5
Yeah, I can see what you are saying, but I would rather have other functionality. In reality all the compiler would do would be to take the actual Global parameter and copy that into the local Formal parameter inside the Function/ Method. Something that the programmer can easily do knowing that they want a local copy of the Global variable. And....this is already available as long as your formal parameter is a different name than the Global variable. I think all of the issues in the past have been where Global variables are passed into a Function/ Sub and the local (formal) variable's name is the same as the Global variable. This is poor form and, although a lot of languages do allow this, it is variable ghosting which is frowned upon. {:0) Brandon Parker
|
|
|
Post by Rod on Feb 27, 2019 10:12:57 GMT -5
There are a couple of things going on. First off the OP is wanting to pass a "Constant" to a sub in the parameter list. He is not really wanting to pass a "Global Value". As Anatoly suggests there may be some merit in passing in global values but you could easily do local=global either before the call and pass it or do it inside the sub.
To use a "Constant" simply use it anywhere. So if xyz=6 then make xyz global and then use xyz as a "Constant" anywhere, absolutely no need to pass it in the parameter list, just use it in the sub or function because it is a "Constant" and you know what it is, its name gives meaning. So spritearray(xyz) gets you what you expect, spritearray(6)
|
|
|
Post by Brandon Parker on Feb 27, 2019 10:59:49 GMT -5
@ carl : PEASE change it so that i can use globals as parameters Well, I referenced "Global" because that is what the message above says. A Global Variable is not the same thing as a Constant in CS. And, like you say, if the value is considered a "Constant" then why pass it; just use the Global Variable one is considering to be a Constant. If....LB had user defined Constants then presumably the compiler would just replace all of the named constants with the literal value during compilation because....Constants are constant and are never changed. Passing a Constant anywhere doesn't make sense because you would be passing a literal value where the literal Constant would already exist and be available, assuming Constants are Global in scope. Otherwise you would have to have Global Constant and Local Constant, but that doesn't make sense because why would you have a two Constant values that have the same name, yet have different values; that's violates what a Constant means and you would then want a variable. {:0) Brandon Parker
|
|
|
Post by tsh73 on Feb 27, 2019 13:18:49 GMT -5
I went and look at code in problem libertybasiccom.proboards.com/thread/468/first-lb5-347-test-resultsit had globals global xyz , xzy , yxz , yzx , zxy , zyx xyz = 0 xzy = 1 yxz = 2 yzx = 3 zxy = 4 zyx = 5 and lines like call link 1 , -200,100,0 , a,a,a , xyz , 0 call cube 0,0,0 , 50,50,50 , "red" , 5 call link 1 , 0,100,0 , a,a,a , yzx , 0 And inside sub link there is select case ax case xyz call matrix.reeks rotx , roty , rotz , trans , p , no case xzy call matrix.reeks rotx , rotz , roty , trans , p , no case yxz call matrix.reeks roty , rotx , rotz , trans , p , no case yzx call matrix.reeks roty , rotz , rotx , trans , p , no case zxy call matrix.reeks rotz , rotx , roty , trans , p , no case zyx call matrix.reeks rotz , roty , rotx , trans , p , no case else end select So yes, it is constants what needs to be passed so decision is made inside. (but there actually a problem is I cannot tell (yet?) I created a sub - and passed global var as parameter - and had no problem - ) EDIT
I think I found the cause sub link has 9 parameters 8 parameters work, 9 fails
|
|
|
Post by Rod on Feb 27, 2019 14:59:28 GMT -5
"Constants" don't need passed, just use them.
|
|
|
Post by tsh73 on Feb 27, 2019 16:35:44 GMT -5
"Constants" don't need passed, just use them. Here: xyz and yzx - constants, meaning something like order of rotation. Go ahead, show us the way to use them without passing.
|
|
|
Post by Brandon Parker on Feb 27, 2019 20:10:29 GMT -5
Like the below.....?
'We are Global Variables, but in this program 'We are pretending to be Constants so do not 'change us. Global xyz : xyz = 0 Global xzy : xyz = 1 Global yxz : yxz = 2 Global yzx : yzx = 3 Global zxy : zxy = 4 Global zyx : zyx = 5
Print myFunction(10, 13) Wait
Function myFunction(someValue, someOtherValue) 'Global variables used below...LB doesn't have Constants so we 'use Globals and just do not every change them myFunction = (someValue * xzy) + (yzx * ((1/3) * someOtherValue) + someValue) - (zyx * sqr(abs(someValue))) End Function
Maybe I'm just not understanding what it is Bluatigro is trying to achieve with the "passing" of a Global Variable.
In my world....I have constants, simple enumerations, macros, and a bunch more in LB4. I wrote my precompiler to do some really heavy lifting of syntax that I made up prior to handing over to LB for tokenizing.
{:0)
Brandon Parker
|
|
|
Post by Carl Gundel on Feb 27, 2019 20:49:23 GMT -5
Like the below.....? <snip> Maybe I'm just not understanding what it is Bluatigro is trying to achieve with the "passing" of a Global Variable. In my world....I have constants, simple enumerations, macros, and a bunch more in LB4. I wrote my precompiler to do some really heavy lifting of syntax that I made up prior to handing over to LB for tokenizing. {:0) Brandon Parker I think the idea is that you pass constants as parameters to control what happens inside subs/functions and you need those named constants also inside the subs/functions so you can compare against the passed in values.
|
|
|
Post by Brandon Parker on Feb 27, 2019 21:06:58 GMT -5
Exactly.... That's what it appears he's doing.... As long as the formal parameter in the function/ subroutine is a different name than the Global ("Constant") then it should be fine. Even then, he's not doing anything with it except checking against the value.
{:0)
Brandon Parker
|
|
|
Post by bluatigro on Feb 28, 2019 3:51:51 GMT -5
why i want global's as parameter's : the code wil be more readeble
if i build a avatar and several animations i do not want to remember all lim number's or build a avartar for every animation [ a hand has 15 lim's ] [ a leg / arm has 3 lim's ] on the moment i declare 64 lim's for a avartar
somtimes i use ulong's as color's because of speed and calculations [ example : raytracing ]
i do not know [ jet ] of a [ errorfree ] way to use matrix's whiout globals
|
|
cundo
Full Member
Muchas Gracias!!
Posts: 146
|
Post by cundo on Feb 28, 2019 9:44:44 GMT -5
Constants are not supose to change, otherwise are just variables. That is the way I learned. Then we have Globals... and constants are global. I think we have two discussions here, one is naming conventions. Ok I don't know what I'm saying sorry haha.
|
|
|
Post by Carl Gundel on Feb 28, 2019 10:56:01 GMT -5
Technically, Liberty BASIC doesn't have a way to declare constants, just variables.
|
|