x := "" MsgBox, % IsFunc("f" (x+1)) MsgBox, % IsFunc("f" (""+1)) f1(){ }
Code to reproduce the issue
Best Answer Lexikos , 12 September 2013 - 11:53 PM
x := "" MsgBox, % IsFunc("f" (x+1)) MsgBox, % IsFunc("f" (""+1)) f1(){ }
Code to reproduce the issue
x := "" MsgBox, % "|" . (x+1) . "|" ; calculated (results in "" because x is empty) MsgBox, % "|" . (""+1) . "|" ; concatenated (because the first value is a literal string)
Prefer ahkscript.org for the time being.
O_o I could've sworn that x+1 returned 1. I suppose that the IsFunc() isn't the problem, then. So, why doesn't x+1 == 1?
But why does blankvar+1 == blank, instead of concat or addition treating blankvar as 0?
What would you expect as the result of adding 1 to nothing?
BTW: It wasn't Lexikos.
Prefer ahkscript.org for the time being.
BTW: It wasn't Lexikos.
The behaviour when using blank values with math operators (blankvar+1) is separate to what VxE described (""+1). VxE is correct.
"" &var
was the main concern for that change, and "" +1
mostly for consistency. Before "" +1
was treated as concatenation, it produced an empty string; i.e. because it is an invalid operation, as was "" & n
(bitwise-and).
a++ b+=1 c:=c+1 MsgBox, % a ", " b ", " c ; 1, 1, Blank
Just me, I thought adding 1 to nothing was 1
Lexikos, you're right, I remember now. I 'wasn't amused' about that change.
GeekDude, sorry, my question wasn't detailed enough. This behaviour is related only to expressions:
Except where noted below, any blank value (empty string) involved in a math operation is not assumed to be zero. Instead, it is treated as an error, which causes that part of the expression to evaluate to an empty string. For example, if the variable X is blank, the expression X+1 yields a blank value rather than 1.
Prefer ahkscript.org for the time being.
a++ b+=1 c:=c+1 MsgBox, % a ", " b ", " c ; 1, 1, BlankJust me, I thought adding 1 to nothing was 1
I get the same result. If I initialize all the variables ahead of time, e.g.
a := b := c := 0
I get the expected result.
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)
If I initialize all the variables ahead of time
That's the point. If I don't have to initialize in most cases, why initialize in some cases?
I agree. It doesn't make sense.
Windows 7 Pro (64 bit) - AutoHotkey v1.1+ (Unicode 32-bit)