Pages: 1 2
Author Topic: Arrays  (96,506 Views)
Offline (Unknown gender) luiscubal

Member
Joined: Jun 2009
Posts: 452
View profile
Reply #15 Posted on: September 14, 2012, 09:48:12 PM
Code (edl) Select

[0, x] = func();


Seems to imply that the first element should be 0. Just like this:

Code (edl) Select

Array res = func();
assert(res[0] == 0);
x = res[1];
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #16 Posted on: September 15, 2012, 12:18:37 PM
Then your code would also assert that the second element should be x, but it doesn't. You implying it should be 0 is just illogical. So I do like the 0 way to do this.
Offline (Unknown gender) polygone

Contributor
Joined: Mar 2009
Posts: 794
View profile
Reply #17 Posted on: September 15, 2012, 03:49:04 PM
These things look like a mess to me.
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #18 Posted on: September 15, 2012, 04:14:37 PM
I am fine with just it being: x = func()[2]
Offline (Unknown gender) Josh @ Dreamland

Prince of all Goldfish
Developer
Joined: Feb 2008
Posts: 2,950
View profile
Reply #19 Posted on: September 15, 2012, 04:34:44 PM
Agreed with HaRRi, again. Zero seems like an elegant solution.

I'd just make them use array subscripts, except it may not always be the case that the function returns an array of only two elements. It may return five, and the user needs only four.
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #20 Posted on: September 15, 2012, 04:59:28 PM
Then maybe this would also work:
[y, z]=func()[1,2]That would also allow changing the order of the return like:
[y, z]=func()[2,1]This would set the second param to z and third to y while leaving the first unused.

But that I think is unneeded. So using [] for a specific value and 0 for an array of values seems the best way.
Offline (Unknown gender) Josh @ Dreamland

Prince of all Goldfish
Developer
Joined: Feb 2008
Posts: 2,950
View profile
Reply #21 Posted on: September 15, 2012, 07:45:55 PM
Unfortunately, GML ambiguates [1,2]. It means the same as [1][2]. Otherwise we could do all sorts of neat array tricks.

Perhaps array[[1,2]] could work.
Offline (Unknown gender) luiscubal

Member
Joined: Jun 2009
Posts: 452
View profile
Reply #22 Posted on: September 16, 2012, 12:26:44 PM
Hmmm...

Code (edl) Select

[x,y,z] = func()[1..3]
Offline (Unknown gender) Josh @ Dreamland

Prince of all Goldfish
Developer
Joined: Feb 2008
Posts: 2,950
View profile
Reply #23 Posted on: September 16, 2012, 02:08:58 PM
If we allow arbitrary element access by using an array as an array subscript, and we let 1..5 be the same as [1, 2, 3, 4, 5] (and maybe let 1..2..9 be [1,3,5,7,9]), then that will work.
Pages: 1 2