[V2 Wish:] Is there any reason that calling f(x*,y*) cannot be supported?

Propose new features and changes
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

[V2 Wish:] Is there any reason that calling f(x*,y*) cannot be supported?

23 Jan 2023, 03:14

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.
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: [V2 Wish:] Is there any reason that f(x*,y*) cannot be supported?

23 Jan 2023, 03:24

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
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: [V2 Wish:] Is there any reason that f(x*,y*) cannot be supported?

23 Jan 2023, 03:59

jNizM wrote:
23 Jan 2023, 03:24
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
}
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.
Descolada
Posts: 1183
Joined: 23 Dec 2021, 02:30

Re: [V2 Wish:] Is there any reason that f(x*,y*) cannot be supported?

23 Jan 2023, 05:47

@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?
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: [V2 Wish:] Is there any reason that f(x*,y*) cannot be supported?

23 Jan 2023, 09:10

Descolada wrote:
23 Jan 2023, 05:47
@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?
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)
AHKV2 will become much smoother and easier in some situations such as creating arrays or generators, if f(*c,a,b,*x) can also be supported in V2 like how Python does.
Descolada
Posts: 1183
Joined: 23 Dec 2021, 02:30

Re: [V2 Wish:] Is there any reason that f(x*,y*) cannot be supported?

23 Jan 2023, 10:24

@V2User ah, I understand now. Instead of

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)
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...
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: [V2 Wish:] Is there any reason that calling f(x*,y*) cannot be supported?

24 Jan 2023, 12:18

I suddenly realized this feature may decrease the readability in func's args.
iseahound
Posts: 1459
Joined: 13 Aug 2016, 21:04
Contact:

Re: [V2 Wish:] Is there any reason that calling f(x*,y*) cannot be supported?

24 Jan 2023, 22:24

Hmm... If Lexikos adds operator overloading, we should get something similar:
image.png
image.png (13.13 KiB) Viewed 1436 times
where f((x + y)*) would work and be more readable?
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: [V2 Wish:] Is there any reason that calling f(x*,y*) cannot be supported?

25 Jan 2023, 01:00

iseahound wrote:
24 Jan 2023, 22:24
Hmm... If Lexikos adds operator overloading, we should get something similar:

image.png

where f((x + y)*) would work and be more readable?
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)
It can also throw more easily and more quickly when x and y's length is not enough.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 7 guests