Should auto concat work with new lines?

Discuss the future of the AutoHotkey language
iseahound
Posts: 1472
Joined: 13 Aug 2016, 21:04
Contact:

Should auto concat work with new lines?

Post by iseahound » 26 Aug 2022, 20:12

I think that some programmers might be under the impression that code without commas at the end work like this:

Code: Select all

() => (
   fn(1) ; missing end comma
   fn(2)
)
but in reality, it's just returning the result of fn(1) concatenated with fn(2). Harmless?
working example

User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

Re: Should auto concat work with new lines?

Post by kczx3 » 26 Aug 2022, 21:13

I’m not at a computer but I’m surprised your example works… I think your parentheses are messed up a bit because you’re trying to call the return value of MsgBox rather than calling your anonymous fat arrow function.

iseahound
Posts: 1472
Joined: 13 Aug 2016, 21:04
Contact:

Re: Should auto concat work with new lines?

Post by iseahound » 26 Aug 2022, 22:59

Well it works fine in Javascript

Code: Select all

alert((() => 'hello world!')())
https://jsfiddle.net/f1wvx5oc/

User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

Re: Should auto concat work with new lines?

Post by kczx3 » 27 Aug 2022, 07:05

Well, in your JavaScript example, you have the parentheses in the correct spots to actually call the anonymous function…

iseahound
Posts: 1472
Joined: 13 Aug 2016, 21:04
Contact:

Re: Should auto concat work with new lines?

Post by iseahound » 27 Aug 2022, 12:46

Code: Select all

alert((() => 'hello world!')())
is equal to:

Code: Select all

MsgBox((() => 'hello world')())
I omitted the parenthesis in function call syntax:

Code: Select all

MsgBox (() => 'hello world')()
It can be a bit confusing because of the significant whitespace :D

User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

Re: Should auto concat work with new lines?

Post by kczx3 » 27 Aug 2022, 18:56

That is confusing. I made an assumption that the first open parenthesis was for the MsgBox but apparently due to the space it is not.

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Should auto concat work with new lines?

Post by Helgef » 28 Aug 2022, 10:43

@iseahound, I think this is the most sensible behaviour for line continuation. It is not clear what you expect, or wish should happen.
I made an assumption that the first open parenthesis was for the MsgBox but apparently due to the space it is not.
Function call wrote:There must be no space between the function name or expression and the open parenthesis which begins the parameter list
I believe this has always been the case, also in v1.

Cheers.

Post Reply

Return to “AutoHotkey Development”