Pages: « 1 2
  Print  
Author Topic: Arrays  (Read 6810 times)
Offline (Unknown gender) luiscubal
Reply #15 Posted on: September 14, 2012, 04:48:12 PM
Member
Joined: Jun 2009
Posts: 452

View Profile Email
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];
Logged
Offline (Unknown gender) TheExDeus
Reply #16 Posted on: September 15, 2012, 07:18:37 AM

Developer
Joined: Apr 2008
Posts: 1863

View Profile
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.
Logged
Offline (Male) polygone
Reply #17 Posted on: September 15, 2012, 10:49:04 AM

Contributor
Location: England
Joined: Mar 2009
Posts: 798

View Profile
These things look like a mess to me.
Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Unknown gender) TheExDeus
Reply #18 Posted on: September 15, 2012, 11:14:37 AM

Developer
Joined: Apr 2008
Posts: 1863

View Profile
I am fine with just it being: x = func()[2]
Logged
Offline (Male) Josh @ Dreamland
Reply #19 Posted on: September 15, 2012, 11:34:44 AM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2954

View Profile Email
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.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) TheExDeus
Reply #20 Posted on: September 15, 2012, 11:59:28 AM

Developer
Joined: Apr 2008
Posts: 1863

View Profile
Then maybe this would also work:
Code: [Select]
[y, z]=func()[1,2]That would also allow changing the order of the return like:
Code: [Select]
[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.
Logged
Offline (Male) Josh @ Dreamland
Reply #21 Posted on: September 15, 2012, 02:45:55 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2954

View Profile Email
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.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) luiscubal
Reply #22 Posted on: September 16, 2012, 07:26:44 AM
Member
Joined: Jun 2009
Posts: 452

View Profile Email
Hmmm...

Code: (EDL) [Select]
[x,y,z] = func()[1..3]
Logged
Offline (Male) Josh @ Dreamland
Reply #23 Posted on: September 16, 2012, 09:08:58 AM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2954

View Profile Email
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.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Pages: « 1 2
  Print