I was wondering about auto-concatenation and lack of parenthesis

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

I was wondering about auto-concatenation and lack of parenthesis

Post by safetycar » 25 Jun 2021, 09:59

I haven't started actually using v2 yet.
But I'm slowly trying to get updated on changes.

So, I had a weird feeling when reading the docs.
I was looking into this code:

Code: Select all

TestToggleEnable(*)
{
    tray.ToggleEnable "TestToggleEnable"
}
My first thought was that it was auto-concatenation.
Later I realized that it's like a function without parenthesis.

I was thinking that this can lead to some issues for newer users.
I'm not even sure I won't fail at some point trying to do some concatenation and actually calling a function by accident.
I have tried to search about the issue because I guess it has been talked about but I couldn't find it by myself.
If there's some relevant link I wouldn't mind checking it.

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: I was wondering about auto-concatenation and lack of parenthesis

Post by safetycar » 25 Jun 2021, 10:31

I'm going to reply to myself :oops:

In the docs ( https://lexikos.github.io/v2/docs/Language.htm#function-calls )
If the return value of the function is not needed and the function name is written at the start of the line (or in other contexts which allow a statement, such as following else or a hotkey), the parentheses can be omitted. In this case, the remainder of the line is taken as the function's parameter list.
So, in the case where auto-concatenation makes sense the functions will be already using parenthesis.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: I was wondering about auto-concatenation and lack of parenthesis

Post by swagfag » 25 Jun 2021, 10:51

it used to be worse in previous versions, but now even if u did commit a mistake that somehow relates to this, chances are the script would throw at some point, so ud at least know something was wrong

personally not a huge fan of the commandlike syntax, only ever use it for MsgBoxes/ToolTips/OutputDebug with strings and such

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: I was wondering about auto-concatenation and lack of parenthesis

Post by safetycar » 25 Jun 2021, 11:03

I'm not a fan either, my worry was more about using it accidentally. (But I had the misconception that parenthesis could be omitted everywhere.)

Post Reply

Return to “Ask for Help (v2)”