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.
Why a function name can't be followed by spaces?
Re: Why a function name can't be followed by spaces?
one thing comes into mind: if (expression) vs function_name (args)
Re: Why a function name can't be followed by spaces?
Thanks Coco.Coco wrote:one thing comes into mind: if (expression) vs function_name (args)
But there is no point, the syntax of if(true), without space is valid in V2.
Re: Why a function name can't be followed by spaces?
AHK has auto-concatenation...
Code: Select all
str := "Hello"
auto_concat := str (str() ? " World" : "")
MsgBox, % auto_concat
str() {
return true
}
Re: Why a function name can't be followed by spaces?
Nice, It's reasonable. I think the syntax of auto-concatenation is ugly.
Thank you.
Thank you.
-
- Posts: 60
- Joined: 03 Oct 2013, 19:49
- Location: Seattle Area
- Contact:
Re: Why a function name can't be followed by spaces?
I love auto concatenation myself, and if you don't like it you can always use the . Operator.
Re: Why a function name can't be followed by spaces?
+1 - so annoying having to use a concatenation operator with other languages...Wade Hatler wrote:I love auto concatenation myself ...
Re: Why a function name can't be followed by spaces?
@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
}
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
}
Re: Why a function name can't be followed by spaces?
Code: Select all
MsgBox (this is not a function call)
Re: Why a function name can't be followed by spaces?
Thanks, you correct my mistakes, MsgBox is indeed a counter example.lexikos wrote:@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.Code: Select all
MsgBox (this is not a function call)
Re: Why a function name can't be followed by spaces?
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.
Re: Why a function name can't be followed by spaces?
I means "printf("%s\n", "123" "abc") is not concatenation".
Re: Why a function name can't be followed by spaces?
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.
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.
Re: Why a function name can't be followed by spaces?
Loop can't be called as a function, yet Loop(x) is a function call. So is Else().just me wrote:If(True) is not a function call, because flow-control commands cannot be called as functions.
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.
Who is online
Users browsing this forum: rc76 and 225 guests