Hallo,
Code: Select all
#Requires AutoHotkey v1.1.33
Label = Text
Goto,% Label++
Text:
This is OK:
Code: Select all
#Requires AutoHotkey v1.1.33
Label = 1
Goto,% Label++
1:
Code: Select all
#Requires AutoHotkey v1.1.33
Label = Text
Goto,% Label++
Text:
Code: Select all
#Requires AutoHotkey v1.1.33
Label = 1
Goto,% Label++
1:
@iseahound, the second code block clearly demonstrates that an expression can be used.Except where noted below, any blank value (empty string) or non-numeric value 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.
Source: Variables and Expressions - Definition & Usage | AutoHotkey v1
Right, that's exactly what I expect.The increment operators cannot produce or consume the value "Text" because it is not a number. The result is instead "".
Code: Select all
#Warn
Label = Text
MsgBox,% Label++ ; it is not treated as an error, but empty!
It is. "Treated as an error" does not mean "displays an error dialog", especially in v1. What it does mean is explicitly stated in the same sentence which says it is treated as an error. I already quoted this.
Instead, it is treated as an error, which causes that part of the expression to evaluate to an empty string.
I think you have a fundamental misunderstanding about how the post-operators work (or imperative programming in general). Think about the impossibility of what you're saying.Rohwedder wrote:As the operator ++ is placed after the variable name, the operation (evaluation to an empty string) may only be carried out after the variable has been used by the MsgBox.
lexikos wrote:The command does not use the variable's value. It never sees the variable. It only sees the result of the expression.
As @lexikos said, the command never uses a value stored in the variable directly. It uses the result of the expression Label++.Rohwedder wrote:The (pre-)result (which the MsgBox has to display here) of the post-incrementation of a variable is the value of the variable before the incrementation ...
Code: Select all
MsgBox,% True++ ; ""
Code: Select all
N = 0
--N++
MsgBox,% N ; 1 , i.e. --N++ works
MsgBox,% --N++ ; "" should be 0
Code: Select all
MsgBox,% N ; 1 , i.e. --N++ works
Code: Select all
N = 0
++N++
MsgBox,% N ; 1 , i.e. ++N++ doesn't work
Seemingly, the first pre-increment/decrement returns a blank result treated as 0.Due to backward compatibility, the operators ++ and -- treat blank variables as zero, but only when they are alone on a line.
Even though it is a standalone statement, it should produce a syntax error, as the docs (and the Standard) indicate they are exclusive constructs:Code: Select all
++N++
From that, it's easy to see things begin to tangle when:Docs wrote:For example, Var := ++X increments X and then assigns its value to Var. Conversely, if the operator appears after the variable's name, the result is the value of X prior to performing the operation. For example, Var := X++ increments X but Var receives the value X had before it was incremented.
Code: Select all
Var := ++X++
I do not understand what is so difficult to understand about this simple sequence of events: first the increment is evaluated, then the MsgBox command is called. There is no such thing as "untouched old content" or "retroactive effect". At the moment the MsgBox command uses its parameter, there is only the current (new) value of the variable, and the result of the expression. The command uses the result of the expression, which as I've pointed out multiple times, is blank due to the non-numeric value, as documented.Rohwedder wrote: ↑03 Mar 2024, 03:40The (pre-)result (which the MsgBox has to display here) of the post-incrementation of a variable is the value of the variable before the incrementation, i.e. the untouched old content!
In the case of a number, exactly this number, in the case of a string, exactly this string.
(But no problem, even bugs have a right to exist.)
Regardless of the order, if both operations were performed on the variable, it should have the same numeric value that it had before the operation, because it is being incremented by 1 and decremented by 1, or vice versa. Yet the first MsgBox shows 1, meaning that the variable was only incremented and not decremented. In other words, "i.e. --N++ works" is a mistake. It does not work. In the standalone --N++, you are never using the final result of the post-increment.Code: Select all
N = 0 --N++ MsgBox,% N ; 1 , i.e. --N++ works MsgBox,% --N++ ; "" should be 0
// DUE TO CODE SIZE AND PERFORMANCE decided not to support things like the following:
...
// -> --Var++ ; Fails because ++ has higher precedence than --, but it produces an operand that isn't
// a variable, so the "--" fails. Things like --Var++ seem pointless anyway because they seem
// nearly identical to the sub-expression (Var+1)? Anyway, --Var++ could probably be supported
// using the loop described in the previous example.
Source: AutoHotkey/source/script_expression.cpp at v1.1.37.01 · AutoHotkey/AutoHotkey · GitHub
I think there are three errors in your statement:lmstearn wrote: ↑05 Mar 2024, 01:54Even though it is a standalone statement, it should produce a syntax error, as the docs (and the Standard) indicate they are exclusive constructs:Code: Select all
++N++