HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

"constant arrays"

04-19-2008, 01:14 AM#1
Vexorian
I am feeling an absurd need to implement this:


Collapse JASS:
globals


   constant integer array SUMMONID=['U000','U001','U002']

endglobals

later:

Collapse JASS:
   set SUMMONID[2] = 3 //error
   
   call BJDebugMsg(I2S(SUMMONID.size()) ) // "3"

   call BJDebugMsg(I2S(SUMMONID[2]) ) // whatever 'U001' translates to.

   

If anybody else would find it useful I might implement it for the next version.
04-19-2008, 01:16 AM#2
Rising_Dusk
Uhm, yes. I was asking for this functionality ages ago in that jasshelper thread, it would be tremendously useful.
04-19-2008, 01:48 AM#3
PandaMine
Definitely yes, could we even form constant matrix's this way?
04-19-2008, 02:01 AM#4
Rising_Dusk
I hate the syntax you've got though, I'm used to the engineering programming languages I use at work.
Collapse JASS:
set u = [1 2 3; 4 5 6]
That would be sexy as hell if we could get matricies like above that worked correctly, but it might be a pain in the ass on your end. If not, at least consider the following implicit array allocation as a possibility:
Collapse JASS:
set u = [1 2 3]
04-19-2008, 02:02 AM#5
TheSecretArts
You know what would be better, multidimensional arrays!
Or matrices, either works.

edit: didnt see other ppl talking about matrices.
04-19-2008, 02:04 AM#6
Rising_Dusk
Quote:
Originally Posted by TheSecretArts
You know what would be better, multidimensional arrays!
Or matrices, either works.
You do realize that a multidimensional array is basically a struct, right? Matricies would use the struct interface internally, but oftentimes for me using a matrix is so much more convenient than defining and working with a struct.
04-19-2008, 02:05 AM#7
Vexorian
Quote:
That would be sexy as hell if we could get matricies like above that worked correctly, but it might be a pain in the ass on your end. If not, at least consider the following implicit array allocation as a possibility:
I don't need that stuff, and it would not help me with what I want, I want to allow people an easy way to type arrays on jesp spells not some sort of macro to avoid typing some assigments

I wouldn't hold my breath for multiple dimensions.
04-19-2008, 02:06 AM#8
TheSecretArts
alas, if I feel up to it, I may just make a matrix system...
04-19-2008, 02:06 AM#9
Rising_Dusk
Quote:
Originally Posted by Vexorian
I don't need that stuff, and it would not help me with what I want, I want to allow people an easy way to type arrays on jesp spells not some sort of macro to avoid typing some assigments

I wouldn't hold my breath for multiple dimensions.
I actually just wrote a system in the past few hours that would've benefited tremendously from matrix allocation, but you 'da boss.
Quote:
Originally Posted by TheSecretArts
alas, if I feel up to it, I may just make a matrix system...
It's not a system for it that I want, it's the syntax.
04-19-2008, 02:27 AM#10
TheSecretArts
I wish, and I doubt its possible, to create a dynamic array with the size of a local...
04-19-2008, 06:16 AM#11
ADOLF
how all this will be is made?

if the index of a file cannot be learned at moment of compilation is it will be simple a array, which is initialized in a stream from main ()? then what for restriction, what it would be impossible to change it?

or it - is simple many constants?
04-19-2008, 11:53 AM#12
Toadcop
ADOLF i will explain what it's...
Vex doing now a hero for the contest and he have a need to do that stuff. and cause he likes high lvl languages etc. he had the idea to implement it into vJass now he have created this thread to proof what he's right.

+ yes it's interesting preproccesor will gen global vars or 1 array ?
if vars so it maybe usefull. (arrays will be in truth very limited usefull.)
it's kind a "just another coding candy"
04-19-2008, 12:31 PM#13
PandaMine
It would be REALLY good that along with constant arrays there would be matrices/matrix's.

The syntax for constant arrays can stay the exact same, just add an extra feature for matrices/matrix, its not that hard
04-19-2008, 02:12 PM#14
Vexorian
So, I will just thinking of stuff, and I have no reason whatsoever not to implement this:

Collapse JASS:
set anything = [1,2,3,a,f(3),x[4]]
Becomes:

Collapse JASS:
set anything[0]=1
set anything[1]=2
set anything[2]=3
set anything[4]=a
set anything[5]=f(3)
set anything[6]=x[4]

Where "anything" is any object that support the []= operator (global arrays, dynamic arrays, structs with overloaded []=, struct array members, ...)

Also

Collapse JASS:
globals
    integer array x=[0,1,2,5,4]
endglobals

becomes:

Collapse JASS:
globals
    integer array x
endglobals

function somethingcalledbeforeanythingelse takes nothing returns nothing
    set x[0]=0
    set x[1]=1
    set x[2]=2
    set x[3]=5
    set x[4]=4
endfunction


Similary:
Collapse JASS:
globals
    constant integer array y=[0,1,2,5,4]
endglobals

Works just like array x, only that you can't change its contents in any function and y.size returns 5.

Just notice that
Collapse JASS:
globals
    integer array A=[1,2,3]
    integer array B=[2,3,4]
    constant integer array C=[2,3,4]
endglobals

function tt takes nothing returns nothing
    set A=B //syntax error
    set A=C //works
endfunction


Mostly because A=B can't be compiled intelligently without converting these normal arrays into "lists" which makes everything too complicated and imho it is overkill.

Eventually, I think it could be made recursive:

Collapse JASS:
type arr extends integer array[3]
type brr extends arr array[3]

function k takes nothing returns nothing
 local brr B=brr.create()
    set B[0]=arr.create()
    set B[1]=arr.create()
    set B[2]=arr.create()

    set B=[[0,1,2],[0,0,4],[1,2,3]]
endfunction

becomes:
Collapse JASS:
   set B[0]=[0,1,2]
   set B[1]=[0,0,4]
   set B[2]=[1,2,2]

which then becomes:

Collapse JASS:
   set B[0][0]=0
   set B[0][1]=1
   set B[0][2]=2
   set B[1][0]=0
   set B[1][1]=0
   set B[1][2]=4
   set B[2][0]=1
   set B[2][1]=2
   set B[2][2]=2

And then is parsed with dynamic array stuff...


Toadcop: you need to calm down else there are going to be consequences. Either way I don't really need this for hero contest or anything in particular, just checking old spells it seemed like something like this would make configuration easier. I am not sure I'll be able to make this addition before the deadline either..
04-19-2008, 04:20 PM#15
Rising_Dusk
That last part interests me the most, though it would be more handy if it could be called like this:
Collapse JASS:
set B[0,0] = 0
set B[3,2] = 2
Also, possible preloading capability?
Collapse JASS:
set C[0,:] = 0
Would set all values in the 0th row of C to 0.