function return Multiple values

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
arcticir
Posts: 639
Joined: 17 Nov 2013, 11:32

function return Multiple values

15 Feb 2020, 06:53

If you need the function to return multiple values. There are several ways:
ByRef - t(ByRef a, ByRef b)
Its disadvantage is that it cannot be nested
t(ByRef a, ByRef b){
;...
if test
t(i,n)
}

obj - t()=>[1,2]
Its disadvantage is that it is too tedious, and value needs to be written multiple times.

macro t()=> (a:=1,b:=2,'')
I do n’t use it because it is very confusing when nested.
Is there a more reasonable way?
Or is it necessary to improve the way the function returns? E.g (a,b):= t()=> 1,2
HotKeyIt
Posts: 2042
Joined: 29 Sep 2013, 18:35
Contact:

Re: function return Multiple values

15 Feb 2020, 15:11

arcticir wrote:
15 Feb 2020, 06:53
obj - t()=>[1,2]
Its disadvantage is that it is too tedious, and value needs to be written multiple times.
Why is this tedious and what do you mean by needs to be written multiple times?

There is another way:

Code: Select all

fun(ObjByRef(p1,p2))
MsgBox p1 "`n" p2
fun(p) => (p.p1:="Test1",p.p2:="Test2",p)
arcticir
Posts: 639
Joined: 17 Nov 2013, 11:32

Re: function return Multiple values

16 Feb 2020, 08:05

Yes, it must be read and written multiple times.
r:=t(),x:=t[1],y:=t[2]
If you ask why t[1]t[2] is not used directly, obviously what is discussed here is how to return multiple values. ;)

V2 has undergone tremendous changes, has many advantages, and is somewhat unacceptable. If the function supports returning multiple values, it's the change I want most.
HotKeyIt
Posts: 2042
Joined: 29 Sep 2013, 18:35
Contact:

Re: function return Multiple values

16 Feb 2020, 08:51

You can use a simple function to convert obj to parameter:

Code: Select all

O2P(fun(),a,b,c)
MsgBox A "`n" B "`n" C
fun(){
  return [1,2,3]
}
O2P(O,ByRef _1:="",ByRef _2:="",ByRef _3:="",ByRef _4:="",ByRef _5:="",ByRef _6:="",ByRef _7:="",ByRef _8:="",ByRef _9:="",ByRef _10:="",ByRef _11:="",ByRef _12:="",ByRef _13:="",ByRef _14:="",ByRef _15:="",ByRef _16:="",ByRef _17:="",ByRef _18:="",ByRef _19:="",ByRef _20:="",ByRef _21:="",ByRef _22:="",ByRef _23:="",ByRef _24:="",ByRef _25:="",ByRef _26:="",ByRef _27:="",ByRef _28:="",ByRef _29:="",ByRef _30:="",ByRef _31:="",ByRef _32:="",ByRef _33:="",ByRef _34:="",ByRef _35:="",ByRef _36:="",ByRef _37:="",ByRef _38:="",ByRef _39:="",ByRef _40:="",ByRef _41:="",ByRef _42:="",ByRef _43:="",ByRef _44:="",ByRef _45:="",ByRef _46:="",ByRef _47:="",ByRef _48:="",ByRef _49:="",ByRef _50:="",ByRef _51:="",ByRef _52:="",ByRef _53:="",ByRef _54:="",ByRef _55:="",ByRef _56:="",ByRef _57:="",ByRef _58:="",ByRef _59:="",ByRef _60:="",ByRef _61:="",ByRef _62:="",ByRef _63:="",ByRef _64:="",ByRef _65:="",ByRef _66:="",ByRef _67:="",ByRef _68:="",ByRef _69:="",ByRef _70:="",ByRef _71:="",ByRef _72:="",ByRef _73:="",ByRef _74:="",ByRef _75:="",ByRef _76:="",ByRef _77:="",ByRef _78:="",ByRef _79:="",ByRef _80:="",ByRef _81:="",ByRef _82:="",ByRef _83:="",ByRef _84:="",ByRef _85:="",ByRef _86:="",ByRef _87:="",ByRef _88:="",ByRef _89:="",ByRef _90:="",ByRef _91:="",ByRef _92:="",ByRef _93:="",ByRef _94:="",ByRef _95:="",ByRef _96:="",ByRef _97:="",ByRef _98:="",ByRef _99:="",ByRef _100:="",ByRef _101:="",ByRef _102:="",ByRef _103:="",ByRef _104:="",ByRef _105:="",ByRef _106:="",ByRef _107:="",ByRef _108:="",ByRef _109:="",ByRef _110:="",ByRef _111:="",ByRef _112:="",ByRef _113:="",ByRef _114:="",ByRef _115:="",ByRef _116:="",ByRef _117:="",ByRef _118:="",ByRef _119:="",ByRef _120:="",ByRef _121:="",ByRef _122:="",ByRef _123:="",ByRef _124:="",ByRef _125:="",ByRef _126:="",ByRef _127:="",ByRef _128:="",ByRef _129:="",ByRef _130:="",ByRef _131:="",ByRef _132:="",ByRef _133:="",ByRef _134:="",ByRef _135:="",ByRef _136:="",ByRef _137:="",ByRef _138:="",ByRef _139:="",ByRef _140:="",ByRef _141:="",ByRef _142:="",ByRef _143:="",ByRef _144:="",ByRef _145:="",ByRef _146:="",ByRef _147:="",ByRef _148:="",ByRef _149:="",ByRef _150:="",ByRef _151:="",ByRef _152:="",ByRef _153:="",ByRef _154:="",ByRef _155:="",ByRef _156:="",ByRef _157:="",ByRef _158:="",ByRef _159:="",ByRef _160:="",ByRef _161:="",ByRef _162:="",ByRef _163:="",ByRef _164:="",ByRef _165:="",ByRef _166:="",ByRef _167:="",ByRef _168:="",ByRef _169:="",ByRef _170:="",ByRef _171:="",ByRef _172:="",ByRef _173:="",ByRef _174:="",ByRef _175:="",ByRef _176:="",ByRef _177:="",ByRef _178:="",ByRef _179:="",ByRef _180:="",ByRef _181:="",ByRef _182:="",ByRef _183:="",ByRef _184:="",ByRef _185:="",ByRef _186:="",ByRef _187:="",ByRef _188:="",ByRef _189:="",ByRef _190:="",ByRef _191:="",ByRef _192:="",ByRef _193:="",ByRef _194:="",ByRef _195:="",ByRef _196:="",ByRef _197:="",ByRef _198:="",ByRef _199:="",ByRef _200:="",ByRef _201:="",ByRef _202:="",ByRef _203:="",ByRef _204:="",ByRef _205:="",ByRef _206:="",ByRef _207:="",ByRef _208:="",ByRef _209:="",ByRef _210:="",ByRef _211:="",ByRef _212:="",ByRef _213:="",ByRef _214:="",ByRef _215:="",ByRef _216:="",ByRef _217:="",ByRef _218:="",ByRef _219:="",ByRef _220:="",ByRef _221:="",ByRef _222:="",ByRef _223:="",ByRef _224:="",ByRef _225:="",ByRef _226:="",ByRef _227:="",ByRef _228:="",ByRef _229:="",ByRef _230:="",ByRef _231:="",ByRef _232:="",ByRef _233:="",ByRef _234:="",ByRef _235:="",ByRef _236:="",ByRef _237:="",ByRef _238:="",ByRef _239:="",ByRef _240:="",ByRef _241:="",ByRef _242:="",ByRef _243:="",ByRef _244:="",ByRef _245:="",ByRef _246:="",ByRef _247:="",ByRef _248:="",ByRef _249:="",ByRef _250:="",ByRef _251:="",ByRef _252:="",ByRef _253:=""){
  for k,v in O
    _%A_Index%:=O[A_Index]
}
To have native support for that, I don't think this is easy to do, also I can't think of a syntax, and even more difficult one that would not destroy current behavior.
arcticir
Posts: 639
Joined: 17 Nov 2013, 11:32

Re: function return Multiple values

16 Feb 2020, 09:40

Thanks. I think "do not break the current" is a pseudo-proposition, because most rules of V1 have been broken by V2.
v2 existing rules are subject to much criticism, are constantly changing, and there is no need to be conservative.

Return to “AutoHotkey_H”

Who is online

Users browsing this forum: No registered users and 25 guests