Qbasicnews.com

General => General/Misc => Topic started by: Z!re on May 02, 2005, 07:17:21 AM



Title: Array mass assignment
Post by: Z!re on May 02, 2005, 07:17:21 AM
Code:
dim arr( 5 ) as ubyte
arr( 0 ) = { 10, 20, 30 }
arr( 3 ) = { 40, 50, 60 }
print arr( 1 ) 'output should be 20
print arr( 4 ) 'output should be 50

It would be really nice to have, IMO

Preferably it should be able to take variables too:
Code:
dim arr( 5 ) as ubyte
arr( 0 ) = { 10, var1, 30 }
arr( 3 ) = { 40, 50, var2 }
print arr( 1 ) 'output should be 'var1'
print arr( 4 ) 'output should be 50


Title: Array mass assignment
Post by: 1000101 on May 03, 2005, 06:38:13 PM
You mean like this?
Code:
Dim a(0 to 9) as ubyte => { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }

Which was implemented in .13?


Title: Array mass assignment
Post by: Z!re on May 03, 2005, 07:53:56 PM
No, not at compile time.

I mean in "realtime"


Read my post again


Title: Array mass assignment
Post by: 1000101 on May 03, 2005, 09:27:09 PM
/me notes your original post said nothing about at compile-time or at run-time.

By the by, it will work at runtime if it can't be resolved at compile time.

I do this for error checking to keep track of which function is currently executed.

ie
Code:
#define _this_proc_ 1
#define _that_proc_ 2

declare sub this_proc ()
declare sub that_proc ()

dim shared CurrentProc as integer

CurrentProc = 0

this_proc
that_proc

End

Sub this_proc ()

   Dim LastProc as integer = CurrentProc
   CurrentProc = _this_proc_

   '' Do stuff

   CurrentProc = LastProc

End sub

Sub that_proc ()

   Dim LastProc as integer = CurrentProc
   CurrentProc = _that_proc_

   '' Do stuff

   CurrentProc = LastProc

End sub


Of cource, my program is a lot more complex which is why I do that, but you get the general idea.

While my example only shows a single variable being auto-assigned at allocation, it still bears proof-of-conciept. :D


Title: Re: Array mass assignment
Post by: Z!re on May 03, 2005, 09:31:27 PM
Quote from: "Z!re"
Code:
dim arr( 5 ) as ubyte
arr( 0 ) = { 10, 20, 30 }
arr( 3 ) = { 40, 50, 60 }
print arr( 1 ) 'output should be 20
print arr( 4 ) 'output should be 50

It would be really nice to have, IMO

Preferably it should be able to take variables too:
Code:
dim arr( 5 ) as ubyte
arr( 0 ) = { 10, var1, 30 }
arr( 3 ) = { 40, 50, var2 }
print arr( 1 ) 'output should be 'var1'
print arr( 4 ) 'output should be 50


Code:
dim arr( 5 ) as ubyte
arr( 0 ) = { 10, var1, 30 }
arr( 3 ) = { 40, 50, var2 }
print arr( 1 ) 'output should be 'var1'
print arr( 4 ) 'output should be 50

arr ( 0 ) = { arr(3), 55, what+that+arr(5) }

print arr(0) 'should = arr(3) (which is 40)
print arr(1) 'should = 55
print arr(2) 'should = what+that+arr(5) (which is= var2)


Note that I DO NOT assign ALL the elements in the array, and that I specify a starting point where to start assigning from.


Title: Array mass assignment
Post by: 1000101 on May 03, 2005, 09:51:42 PM
True enough, but your request wasn't specific enough to draw any conclusions from.  I was operating on the assumption that you weren't aware of declaration assignments.

Still, in the example you gave, the compiler would end up optimizing that to be a compile time assignment with the unknowns filled with nulls.

But, assuming you were using vairables instead of litterals, then that would have some value.  I see what you are getting at, however, you should be more specific in the future ;P