how can initialize an array of arrays in vex?
6277
4
0
pelos
Member
623 posts
Joined: Aug. 2008
Offline
Jan. 6, 2019 4 a.m.
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 {{}, {}, {} }
Aizatulin
Member
502 posts
Joined: July 2005
Offline
Jan. 6, 2019 5:47 a.m.
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
bonsak
Member
459 posts
Joined: Oct. 2011
Offline
Jan. 6, 2019 6:39 a.m.
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
pelos
Member
623 posts
Joined: Aug. 2008
Offline
Jan. 6, 2019 10:59 p.m.
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
bonsak
Member
459 posts
Joined: Oct. 2011
Offline
Jan. 7, 2019 2:56 a.m.
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