Could the usage x1:=x1??x2??x3??x4??x5 be formally documented?

Share your ideas as to how the documentation can be improved.
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Could the usage x1:=x1??x2??x3??x4??x5 be formally documented?

01 Aug 2023, 13:08

Could the usage of x1:=x1??x2??x3??x4??x5 be formally documented or it's just an "unintentional feature"?
Code:

Code: Select all

x5:=7,x3:=9
x1:=x1??x2??x3??x4??x5
OutputDebug(x1)
x1:=x1??x2??x3??x4??x5 will be totally equivalent to this code below:

Code: Select all

x1:=x1??(x2?)
,x1:=x1??(x3?)
,x1:=x1??(x4?)
,x1:=x1??x5
After testing, the usage of x1:=x1??x2??x3??x4??x5 works well currently, however undocumented.
Last edited by V2User on 01 Aug 2023, 19:19, edited 3 times in total.
Michaohneel
Posts: 7
Joined: 07 Feb 2021, 16:37
Contact:

Re: Could the usage x1:=x1??x2??x3??x4??x5 be formally documented?

01 Aug 2023, 14:13

I'm not sure what you think should be documented about this, that's just how operators work, isn't it?
All operators (with very few exceptions, which are documented) are evaluated from left to right. So just like 1 + 2 + 3 evaluates 1 + 2 first, and then + 3 to the result of that, a ?? b ?? c evaluates a ?? b first and then ?? c to the result of that.
Since x ?? y is just a shorthand for isSet(x) ? x : y, you may also look at it this way: a ?? b ?? c is equivalent to isSet(a) ? a : isSet(b) ? b : c. Now, in my opinion, that looks much more confusing and might actually be worth documenting. But even this case follows basic laws of infix operators (it just looks complicated because the ternary operator has, as the name suggests, three operands).

The only operators which are evaluated from right to left (it's called right-associativity) are the assignment operators (:= and its siblings) and the power operator (**). And both of which clearly say that in the documentation.

So, unless I'm missing something, I think this should either be documented more broadly, for all left-associative operators, or left as is.
Come talk to me over on the Discord server :)
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: Could the usage x1:=x1??x2??x3??x4??x5 be formally documented?

01 Aug 2023, 15:32

Michaohneel wrote:
01 Aug 2023, 14:13
I'm not sure what you think should be documented about this, that's just how operators work, isn't it?
All operators (with very few exceptions, which are documented) are evaluated from left to right. So just like 1 + 2 + 3 evaluates 1 + 2 first, and then + 3 to the result of that, a ?? b ?? c evaluates a ?? b first and then ?? c to the result of that.
Since x ?? y is just a shorthand for isSet(x) ? x : y, you may also look at it this way: a ?? b ?? c is equivalent to isSet(a) ? a : isSet(b) ? b : c. Now, in my opinion, that looks much more confusing and might actually be worth documenting. But even this case follows basic laws of infix operators (it just looks complicated because the ternary operator has, as the name suggests, three operands).

The only operators which are evaluated from right to left (it's called right-associativity) are the assignment operators (:= and its siblings) and the power operator (**). And both of which clearly say that in the documentation.

So, unless I'm missing something, I think this should either be documented more broadly, for all left-associative operators, or left as is.
Because expressions are not supported prior to ?? currently, from what has been described in the document.
image.png
image.png (210.84 KiB) Viewed 1082 times
x1:=(x1??x2)??x3??x4??(x5?) will throw an error but x1:=x1??x2??x3??x4??(x5?) will not. The usage of x1:=x1??x2??x3??x4??x5 may be deleted as well in the future update if it's an undocumented usage. At that time, all of the codes on this usage have to be rewritten. So currently, you are not able to apply this usage to your codes with confidence. As similar things have happened to V2.0.4.
https://www.autohotkey.com/boards/viewt ... er%20this.
lexikos
Posts: 9665
Joined: 30 Sep 2013, 04:07
Contact:

Re: Could the usage x1:=x1??x2??x3??x4??x5 be formally documented?

01 Aug 2023, 19:25

If I say both operands of + must be a number, does that mean (a * b) + 1 is undocumented because it doesn't say what happens when the left operand is a multiplication expression in parentheses? No.

In x1 ?? x2 ?? x3, the left operand of the second ?? is either x1 or x2; in either case, a variable.

Strictly speaking, (x1 ?? x2) ?? x3 should work but currently doesn't due to undocumented limitations. I think this will be fixed by v2.1, but in the meantime, just don't do that.

Right-associativity means that x1 ?? x2 ?? x3 would be evaluated as x1 ?? (x2 ?? x3) and not (x1 ?? x2) ?? x3, but putting aside the above limitation, it isn't possible to observe the difference because variable references have no side-effects. Either way, if the first operand is unset, the second operand isn't evaluated at all.

Return to “Suggestions on Documentation Improvements”

Who is online

Users browsing this forum: No registered users and 3 guests