@eugenesv, one-liner functions are already available in v2 as fat arrow functions:
Sum(a, b) => a+b
or from your example
hk1(ThisHotkey) => SendInput('{Blind}{NumpadDiv}')
At one point there comes the question whether a one-liner is worth the terseness over readability and debuggability.
Consider this hotkey:
x::MouseMove(100,100)
I would say this is understandable at a glance: a hotkey which moves the cursor to a specific point. This is quite fine, as is the fat arrow function example above.
What about this one:
x::MouseGetPos(&X, &Y), X=100 && Y=100 ? MouseMove(200, 200) : MouseMove(100, 100)
It is still understandable if one is familiar with multi-statement expressions and ternaries. However I would argue that the following is more readable, easier for other people (especially beginners) to understand, and easier to debug (you can set break-points for the separate lines and then inspect variable contents etc):
Code: Select all
x::
{
MouseGetPos(&X, &Y)
if X = 100 and Y = 100
MouseMove(200, 200)
else
MouseMove(100, 100)
}
This one?
x::Looper:=((n) => --n>0 && (MouseGetPos(&X, &Y), X=100 && Y=100 ? MouseMove(200, 200) : MouseMove(100, 100), Sleep(250), Looper(n-1))), Looper(10)
I would hate to debug that, and understanding it takes considerable effort. I would much prefer
Code: Select all
x::
{
n := 10
while --n > 0 {
MouseGetPos(&X, &Y)
if X = 100 and Y = 100
MouseMove(200, 200)
else
MouseMove(100, 100)
Sleep(250)
}
}
So the questions is, what are possible common scenarios where you would desire a one-liner loop, where readability would still be okay?