|
Post by matty47 on May 22, 2023 4:37:51 GMT -6
It would seem that subs and functions must be written before they can be called? (I have been used to writing function after the main code loop.)
If I say use "i" as index variable in a for loop, to reuse "i" as index in a later for loop I need to "dim i" or I get an error.
If I have a variable say "d" the compiler complains if I try to us "d" as a function parameter - item already exists in this scope.
|
|
|
Post by johnno56 on May 22, 2023 5:57:53 GMT -6
Jumping from one Basic to another, there are times that I get one of those 'forehead slaps' because I had forgotten 'before or after' the code... The problem with that is there does not seem to be a 'standard' for stuff like that. I think things like that are designed to 'keep us on our toes'...
As to the other two issues, I do not believe that I have personally come across those... Perhaps Admin can answer that one... I can remember getting something like that, when using QB64, when I forget to use 'Dim Shared variable'. Perhaps having something like that in RCBasic might take care of that problem? Perhaps a 'feature request'?
I am sorry that I could not be of much help...
|
|
|
Post by aurel on May 22, 2023 7:44:55 GMT -6
well i agree sometimes is strange but as johnno says every dialect have something different in o2 i can use both method in my own interpreter i can also put it anywhere because is global.
|
|
|
Post by n00b on May 22, 2023 8:10:35 GMT -6
It would seem that subs and functions must be written before they can be called? (I have been used to writing function after the main code loop.)
Yes. RCBasic parses output line by line. You must make variables and functions/subs before you can use them. If I say use "i" as index variable in a for loop, to reuse "i" as index in a later for loop I need to "dim i" or I get an error. Yes. If i does not exists it will create the variable i in the FOR loop scope so it won't we accessible outside that loop. If I have a variable say "d" the compiler complains if I try to us "d" as a function parameter - item already exists in this scope.
If a variable is created globally (outside a function) and a function is created after it, that function will be able to access that variable. NOTE: You can refer to the SCOPE and INTRO TO PROGRAMMING sections in the manual for explanations on this. I should probably go in and try to add some better explanations before the next release.
|
|
|
Post by matty47 on May 25, 2023 23:21:53 GMT -6
Just a quick example to illustrate my third observation
i = 0
function increment(i) i = i+1 return i end Function
y=increment(10) print (y)
This fails to compile with error "ERROR:Function argument identifier already exists in current scope
Error on Line 3 in dimTest.bas: Function argument identifier already exists in current scope
Compile Failed"
But this code will compile
function increment(i) i = i+1 return i end Function
i = 0
y=increment(10) print (y)
|
|
|
Post by n00b on May 26, 2023 0:24:50 GMT -6
When you add an argument to a function, you are creating a new variable. If that variable already exists you can't create it again.
|
|
|
Post by aurel on May 26, 2023 3:31:58 GMT -6
yes i am not sure what is not clear here only in case you are used to different syntax
like
Global i
or
Dim Shared i As integer
or something like that ?
|
|