[V2 Wish:] Wish to support one-line if

Propose new features and changes
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

[V2 Wish:] Wish to support one-line if

Post by V2User » 30 Jan 2023, 04:37

Wish to support one-line if with braces, like this:

Code: Select all

if (true){OutputDebug(77)}
Nearly all languages with brace syntax such as JS, Java, etc. can write like that.

iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: [V2 Wish:] Wish to support one-line if

Post by iseahound » 30 Jan 2023, 10:49

I generally use the boolean operators.

Code: Select all

if (b == "")
   b := 1
   
 ; becomes
(b == "") && b := 1

; Lift color to 32-bits if first 8 bits are zero.
if not (color >> 24)
   color |= 0xFF000000

; Becomes
(color >> 24) || color |= 0xFF000000
Note 1: The beginning must have an open parentheses. This acts as a guard to prevent !a && a := 3 from being appended to the previous line.
Note 2: The assignment operator has its precedence lifted. See https://www.autohotkey.com/docs/v1/Variables.htm#AssignOp
The precedence of the assignment operators is automatically raised when it would avoid a syntax error or provide more intuitive behavior. For example: not x:=y is evaluated as not (x:=y). Similarly, ++Var := X is evaluated as ++(Var := X); and Z>0 ? X:=2 : Y:=2 is evaluated as Z>0 ? (X:=2) : (Y:=2).

User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: [V2 Wish:] Wish to support one-line if

Post by V2User » 14 Feb 2023, 10:51

iseahound wrote:
30 Jan 2023, 10:49
I generally use the boolean operators.

Code: Select all

if (b == "")
   b := 1
   
 ; becomes
(b == "") && b := 1

; Lift color to 32-bits if first 8 bits are zero.
if not (color >> 24)
   color |= 0xFF000000

; Becomes
(color >> 24) || color |= 0xFF000000
Note 1: The beginning must have an open parentheses. This acts as a guard to prevent !a && a := 3 from being appended to the previous line.
Note 2: The assignment operator has its precedence lifted. See https://www.autohotkey.com/docs/v1/Variables.htm#AssignOp
The precedence of the assignment operators is automatically raised when it would avoid a syntax error or provide more intuitive behavior. For example: not x:=y is evaluated as not (x:=y). Similarly, ++Var := X is evaluated as ++(Var := X); and Z>0 ? X:=2 : Y:=2 is evaluated as Z>0 ? (X:=2) : (Y:=2).
Thank you very much. It really helps me. And I am sorry for the late reply as I didn't see it until now.

Post Reply

Return to “Wish List”