Post Reply 
Sub-routine returning multiple values
10-30-2017, 01:14 AM
Post: #2
RE: Sub-routine returning multiple values
(10-30-2017 12:48 AM)Jacob Wall Wrote:  I haven't found any mention of it, but thought that it might be something already implemented?

What I'm curious about is having a sub-routine calculating multiple values and returning those values back to the function that called it. Currently what I'm doing is returning a list of values form the sub-routine, then one by one assigning to the variables I want. A completely made-up example illustrating what I'm talking about:

Code:
...
  my_vars:=Sub_Routine(a,b,c);
  d:=my_vars(1);
  e:=my_vars(2);
  f:=my_vars(3);
...

Sub_Routine(x,y,z)
BEGIN
  RETURN({x+1,y+2,z+3});
END;

It would be handy to be able to reduce the four lines to a single line, some like (d,e,f):=Sub_Routine(a,b,c); or something like that. I haven't fully thought this through yet, but couldn't help thinking there could be a better way.

Any insights or further thought?

You could have the sub return a list of values.

Code:
BEGIN
  LOCAL mylist;
  mylist:=MAKELIST(0,C,1,3); 
  mylist(1):=x;
  mylist(2):=y+2;
  mylist(3):=z+3;
  RETURN mylist;
END;

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Sub-routine returning multiple values - toml_12953 - 10-30-2017 01:14 AM



User(s) browsing this thread: 1 Guest(s)