[V2 Wish:] Is there any reason that calling f(x*,y*) cannot be supported?
[V2 Wish:] Is there any reason that calling f(x*,y*) cannot be supported?
As some other languages such as Python can support a call to functions like f(x*,a,c,y*). So I wish AHKV2 could support f(x*,y*) as well.
Last edited by V2User on 23 Jan 2023, 11:21, edited 1 time in total.
Re: [V2 Wish:] Is there any reason that f(x*,y*) cannot be supported?
You can already do something similar. Just pass an array.
Code: Select all
#Requires AutoHotkey v2.0
f([1, 2, 3], 4, 5, 6, 7, 8, 9)
f(x, a, c, y*)
{
loop x.Length
MsgBox A_Index
MsgBox a
MsgBox c
for i, p in y
MsgBox p
}
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: [V2 Wish:] Is there any reason that f(x*,y*) cannot be supported?
It's not the same. In what I wish, the position of args can be switched anytime you want, such as f(r*)=>r, f(a,x*,c,y*). But f(x,a,c,y) in your code cannot switch.jNizM wrote: ↑23 Jan 2023, 03:24You can already do something similar. Just pass an array.
Code: Select all
#Requires AutoHotkey v2.0 f([1, 2, 3], 4, 5, 6, 7, 8, 9) f(x, a, c, y*) { loop x.Length MsgBox A_Index MsgBox a MsgBox c for i, p in y MsgBox p }
Re: [V2 Wish:] Is there any reason that f(x*,y*) cannot be supported?
@V2User, could you provide a working example of such a function in Python?
Namely I can't figure out how that should work. f(x*,a,c,y*) called with f(1,2,3,4,5) - what values would a and b be in that case?
Namely I can't figure out how that should work. f(x*,a,c,y*) called with f(1,2,3,4,5) - what values would a and b be in that case?
Re: [V2 Wish:] Is there any reason that f(x*,y*) cannot be supported?
You have misunderstood me. I mean use f(x*,a,c,y*) in a function call, not in a function definition. This can run very smoothly in python:
Code: Select all
def f(*c):
return c
x=[7,9,5]
a=11
b=99
c=[17,0,3]
cc=f(*c,a,b,*x)
for x in cc:
print(x)
Re: [V2 Wish:] Is there any reason that f(x*,y*) cannot be supported?
@V2User ah, I understand now. Instead of
you'd like for arrays to also be expanded even when not the last argument, like cc:=f(c*,a,b,x*). That'd be nice indeed...
Code: Select all
f(c*) => c
x:=[7,9,5]
a:=11
b:=99
c:=[17,0,3]
cc:=f.Bind(c*)(a,b,x*)
for x in cc
OutputDebug(x)
Re: [V2 Wish:] Is there any reason that calling f(x*,y*) cannot be supported?
I suddenly realized this feature may decrease the readability in func's args.
Re: [V2 Wish:] Is there any reason that calling f(x*,y*) cannot be supported?
Hmm... If Lexikos adds operator overloading, we should get something similar:
where f((x + y)*) would work and be more readable?
where f((x + y)*) would work and be more readable?
Re: [V2 Wish:] Is there any reason that calling f(x*,y*) cannot be supported?
Sure, it is the same. So, I think this feature I proposed can be considered anyway. We may use f(x*,y*,5:v, v,v) to indicate the position of the next arg to keep the readabilities of func's args when the next arg is not variadic:
Code: Select all
f(a,b,c,d,e,f,g*){
}
x:=[0,0,0],y:=[0],v:=7
f(x*,y*,5:v,v,v)
Who is online
Users browsing this forum: No registered users and 7 guests