how can initialize an array of arrays in vex?

   4477   4   0
User Avatar
Member
614 posts
Joined: Aug. 2008
Offline
how can initialize an array of arrays in vex?

i know in python would look like
my_array =
for i in range(4):
my_array.append()
print(my_array)
>>>[ , , , , ]


this is how i am trying to do in vex
int liners;
for(int l = 0; l < ch(“loops”); ++l){
int mini_liner;
push(liners, mini_liner);
};

but when i printf i just get
{}
and that's it i was expecting something like {{}, {}, {} }
User Avatar
Member
471 posts
Joined: July 2005
Offline
Hi,

I think this is not possible in VEX . It would be very nice, if there were something like container classes/templates in VEX, to create custom arrays and the ability to gain control over more abstract structures. For example, if you want to sort an array of a special type in VEX it is very painful (As workaround in Python this quite easy). So what I am dreaming of are templates and functional programming stuff in VEX. But I know it will be a hard task to do that, since everything else has to be consistent.
Edited by Aizatulin - Jan. 6, 2019 05:50:27
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
You could hack it by using a matrix data type as your inner array:
matrix outsidearray[];
matrix insidearray = set(0,1,2,3,4,5,6,7,8);

for(int i; i < 10; i++){
    append(outsidearray, insidearray);
}

//float component = getcomp(outsidearray[0],0,0);
printf('%g', outsidearray);

But you will not get array functionality in the inner array.

Regards
Bonsak
http://www.racecar.no [www.racecar.no]
User Avatar
Member
614 posts
Joined: Aug. 2008
Offline
mmm can I make a dictionary where values are arrays?
    mydic{}

    dic[0]= [1,2,3....]
something like that?
Edited by pelos - Jan. 6, 2019 23:10:28
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Not in vex put in python.
mydict = {}
mydict[0] = [1,2,3,4,5,6,7,8,9]
print mydict[0][0]
1
Or with a list of lists:
mylist = []
mylist.append([1,2,3,4,5,6,7,8,9])
print mylist[0][0]
1
Its still not true arrays though.

Regards
Bonsak
http://www.racecar.no [www.racecar.no]
  • Quick Links