!x() ? y : z treated as an error

Discuss the future of the AutoHotkey language
coffee
Posts: 21
Joined: 01 Apr 2017, 07:55

!x() ? y : z treated as an error

16 Jul 2017, 15:17

[Moderator's note: Topic split from DirExist() change?]
lexikos wrote:Fixed in v2.0-a081.

Thank youuu.

Another question. Feel free to split it from this thread if you deem it necessary.

In v2 a078 you can do (and in v1.1 with the command wrapped as function)

Code: [Select all] [Download] GeSHi © Codebox Plus

!ProcessExist("firefox.exe") ? x:=0 : x:=1
msgbox(x)

and it works.

But in v2 a080 and a081 that same example is treated as a syntax error because of the "!" . You would have to wrap it in parenthesis (!ProcessExist("firefox.exe"))
Is it possible to re-allow the ! operator to be in the beginning of the line?
lexikos
Posts: 5407
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: !x() ? y : z treated as an error

17 Jul 2017, 02:53

It is not treated as a syntax because of the "!", or at all. The code you posted works just fine as its own script in v2.0-a081.

Starting the line with ! is only possible if it is the very first line in the script, because ! is a continuation-line character in both v1 and v2. It has been this way for a very long time.

Another question. Feel free to split it from this thread if you deem it necessary.

Your question has nothing to do with the original topic, so I am obliged to split it, even though doing so is a waste of my time. Surely it would have been just as easy for you to start a new topic as to write this.
just me
Posts: 4371
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: !x() ? y : z treated as an error

17 Jul 2017, 03:05

FYI (because I already prepared an answer):
Tested on 1.1.25.02:

Code: [Select all] [Download] GeSHi © Codebox Plus

y := 0
!AlwaysFalse("firefox.exe") ? x:=0 : x:=1
MsgBox, x = %x% - y = %y% ; x = 0 - y =

AlwaysFalse(P*) {
Return False
}


Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox, Hello! ; Hello! !AlwaysFalse("firefox.exe") ? x:=0 : x:=1
!AlwaysFalse("firefox.exe") ? x:=0 : x:=1
MsgBox, x = %x% ; x =

AlwaysFalse(P*) {
Return False
}


Splitting a Long Line into a Series of Shorter Ones
Method #1: A line that starts with "and", "or", ||, &&, a comma, or a period is automatically merged with the line directly above it (in v1.0.46+, the same is true for all other expression operators except ++ and --).
Use ListLines to see what happens.
coffee
Posts: 21
Joined: 01 Apr 2017, 07:55

Re: !x() ? y : z treated as an error

17 Jul 2017, 13:38

just me wrote:FYI (because I already prepared an answer):
Tested on 1.1.25.02:

Code: [Select all] [Download] GeSHi © Codebox Plus

y := 0
!AlwaysFalse("firefox.exe") ? x:=0 : x:=1
MsgBox, x = %x% - y = %y% ; x = 0 - y =

AlwaysFalse(P*) {
Return False
}


Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox, Hello! ; Hello! !AlwaysFalse("firefox.exe") ? x:=0 : x:=1
!AlwaysFalse("firefox.exe") ? x:=0 : x:=1
MsgBox, x = %x% ; x =

AlwaysFalse(P*) {
Return False
}


Splitting a Long Line into a Series of Shorter Ones
Method #1: A line that starts with "and", "or", ||, &&, a comma, or a period is automatically merged with the line directly above it (in v1.0.46+, the same is true for all other expression operators except ++ and --).
Use ListLines to see what happens.

Yeap, I see it now. The issue was that I had most of the commands wrapped as functions. I never really used commands, unless they couldn't be wrapped into a function.
If you use that second example and wrap msgbox as a function, the ! in the next line does not get appended to the string, but kind of like to the msgbox function call and the next call below continues normally. Which lead me to assume that operator merging rule didn't apply to !
There was no error, so no need for me to follow it through listlines.

Code: [Select all] [Download] GeSHi © Codebox Plus

Msgbox("hello!") ; Hello!
!AlwaysFalse("firefox.exe") ? x:=0 : x:=1
MsgBox, x = %x% ; x = 0

AlwaysFalse(P*) {
Return False
}


I suppose it was a lack of checking on v1 that allowed me to do that , which when moved to v2 080 it threw the exception.
Since this is how it translated as a line and worked, even on v2 078.

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox("Hello!") !AlwaysFalse("firefox.exe") ? x:=0 : x:=1
lexikos
Posts: 5407
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: !x() ? y : z treated as an error

19 Jul 2017, 03:54

coffee wrote:If you use that second example and wrap msgbox as a function, the ! in the next line does not get appended to the string, but kind of like to the msgbox function call and the next call below continues normally.
Why would something outside the parentheses get appended to one of the function's parameters? Of course it wouldn't. Would you expect x in MsgBox(y) x to appear in the MsgBox?

MsgBox("foo") !x ? y : z may have the right effect, but it is encountering a silent (in v1) error condition every time.

0 !1 does not perform auto-concat. The reasons for this can be found in the source code:

Code: [Select all] [Download] GeSHi © Codebox Plus

// If what lies to its left is a CPARAN or OPERAND, SYM_CONCAT is not auto-inserted because:
// 1) Allows ! and ~ to potentially be overloaded to become binary and unary operators in the future.
// 2) Keeps the behavior consistent with unary minus, which could never auto-concat since it would
// always be seen as the binary subtract operator in such cases.
// 3) Simplifies the code.

0 !1 pushes two values onto the stack, performs "NOT", and then finishes the expression with too many values on the stack. This is treated as an error (because it is invariably the result of a syntax error) and the expression yields a blank result. MsgBox % 0 !1 (optionally with a line break before "!") therefore shows blank.

MsgBox("foo") !x ? y : z is the same, but MsgBox is called as part of the expression and therefore before the error condition is encountered.
coffee
Posts: 21
Joined: 01 Apr 2017, 07:55

Re: !x() ? y : z treated as an error

19 Jul 2017, 16:06

lexikos wrote:
coffee wrote:If you use that second example and wrap msgbox as a function, the ! in the next line does not get appended to the string, but kind of like to the msgbox function call and the next call below continues normally.

Why would something outside the parentheses get appended to one of the function's parameters? Of course it wouldn't. Would you expect x in MsgBox(y) x to appear in the MsgBox?
Nope, neither would I expect that nor was I expecting that, and that wasn't what I said either. I was replying to just me pointing him how his use case with commands yielded a different result from a use case with functions and why I was always silent erroring. It was improper syntax on my part, I changed my scripts, case closed.

lexikos wrote:MsgBox("foo") !x ? y : z may have the right effect, but it is encountering a silent (in v1) error condition every time.

0 !1 does not perform auto-concat. The reasons for this can be found in the source code:

Code: [Select all] [Download] GeSHi © Codebox Plus

// If what lies to its left is a CPARAN or OPERAND, SYM_CONCAT is not auto-inserted because:
// 1) Allows ! and ~ to potentially be overloaded to become binary and unary operators in the future.
// 2) Keeps the behavior consistent with unary minus, which could never auto-concat since it would
// always be seen as the binary subtract operator in such cases.
// 3) Simplifies the code.

0 !1 pushes two values onto the stack, performs "NOT", and then finishes the expression with too many values on the stack. This is treated as an error (because it is invariably the result of a syntax error) and the expression yields a blank result. MsgBox % 0 !1 (optionally with a line break before "!") therefore shows blank.

MsgBox("foo") !x ? y : z is the same, but MsgBox is called as part of the expression and therefore before the error condition is encountered.

Thank you for this.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 3 guests