Why a function name can't be followed by spaces?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
isurface
Posts: 14
Joined: 20 Oct 2013, 04:07

Why a function name can't be followed by spaces?

06 Nov 2013, 10:44

There is a comment is source code : Can't be a function definition or call without an open-parenthesis as first char found by the above.
Is there any problems with spaces?

Thanks.
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: Why a function name can't be followed by spaces?

06 Nov 2013, 10:50

one thing comes into mind: if (expression) vs function_name (args)
isurface
Posts: 14
Joined: 20 Oct 2013, 04:07

Re: Why a function name can't be followed by spaces?

06 Nov 2013, 10:57

Coco wrote:one thing comes into mind: if (expression) vs function_name (args)
Thanks Coco.

But there is no point, the syntax of if(true), without space is valid in V2.
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: Why a function name can't be followed by spaces?

06 Nov 2013, 11:06

AHK has auto-concatenation...

Code: Select all

str := "Hello"
auto_concat := str (str() ? " World" : "")
MsgBox, % auto_concat

str() {
	return true
}
isurface
Posts: 14
Joined: 20 Oct 2013, 04:07

Re: Why a function name can't be followed by spaces?

06 Nov 2013, 20:02

Nice, It's reasonable. I think the syntax of auto-concatenation is ugly.

Thank you.
Wade Hatler
Posts: 60
Joined: 03 Oct 2013, 19:49
Location: Seattle Area
Contact:

Re: Why a function name can't be followed by spaces?

06 Nov 2013, 22:27

I love auto concatenation myself, and if you don't like it you can always use the . Operator.
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: Why a function name can't be followed by spaces?

07 Nov 2013, 00:36

Wade Hatler wrote:I love auto concatenation myself ...
+1 - so annoying having to use a concatenation operator with other languages...
isurface
Posts: 14
Joined: 20 Oct 2013, 04:07

Re: Why a function name can't be followed by spaces?

07 Nov 2013, 01:28

@Coco, @jethrow

In fact, there is also a concatenation in C language.
printf("%s\n", "123" "abc")
It will output: 123abc

However, printf("%s\n", str ("123")) will arises an error, if stris not a pointer to function. So I think AHK also can support space follow by function name. And the logic is very simple, when script gets a line as this: str ("123"), script knows what str is:
if (str is var)
{
treat str as var
}
else if(str is func or str doesn't define))
{
treat str as function
}
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Why a function name can't be followed by spaces?

07 Nov 2013, 02:20

Code: Select all

MsgBox (this is not a function call)
@isurface: That's not concatenation. It's a function call with a string containing format codes. Part of the library, not the language. It's also totally different to AutoHotkey's auto-concatenation.
isurface
Posts: 14
Joined: 20 Oct 2013, 04:07

Re: Why a function name can't be followed by spaces?

07 Nov 2013, 02:51

lexikos wrote:

Code: Select all

MsgBox (this is not a function call)
@isurface: That's not concatenation. It's a function call with a string containing format codes. Part of the library, not the language. It's also totally different to AutoHotkey's auto-concatenation.
Thanks, you correct my mistakes, MsgBox is indeed a counter example.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Why a function name can't be followed by spaces?

07 Nov 2013, 16:25

I'm not sure what you mean by that. The example was not aimed at you, hence being written above "@isurface" rather than below it. I was simply showing another reason why x () is not a function call.
isurface
Posts: 14
Joined: 20 Oct 2013, 04:07

Re: Why a function name can't be followed by spaces?

07 Nov 2013, 23:36

I means "printf("%s\n", "123" "abc") is not concatenation".
just me
Posts: 9451
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Why a function name can't be followed by spaces?

09 Nov 2013, 01:17

Every programming language has syntax rules. One of AutoHotkey's is: When a function is defined, its parameters are listed in parentheses next to its name (there must be no spaces between its name and the open-parenthesis). If(True) is not a function call, because flow-control commands cannot be called as functions. That's it.

If you want this to be changed, you might place a change request in 'Wish List'.

BTW: Personally, I don't like the auto-concat feature, because I don't want that the script parser will imply what I 'm intending. Also, I'd prefer to get "Error: This line does not contain a recognized action." for things like If(Var). But it's just me. ;)
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Why a function name can't be followed by spaces?

10 Nov 2013, 01:46

just me wrote:If(True) is not a function call, because flow-control commands cannot be called as functions.
Loop can't be called as a function, yet Loop(x) is a function call. So is Else().

The real reason is that there are exceptions for IF and WHILE, since it is common for users of other languages to habitually write if() or while(). Secondary reasons are that there's no plausible use for functions named if() or while(), and nothing else the user could be intending.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: rc76 and 225 guests