Page 1 of 1

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

Posted: 16 Jul 2017, 15:17
by coffee
[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

!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?

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

Posted: 17 Jul 2017, 02:53
by lexikos
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.

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

Posted: 17 Jul 2017, 03:05
by just me
FYI (because I already prepared an answer):
Tested on 1.1.25.02:

Code: Select all

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

AlwaysFalse(P*) {
   Return False
}

Code: Select all

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.

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

Posted: 17 Jul 2017, 13:38
by coffee
just me wrote:FYI (because I already prepared an answer):
Tested on 1.1.25.02:

Code: Select all

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

AlwaysFalse(P*) {
   Return False
}

Code: Select all

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

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

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

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

Posted: 19 Jul 2017, 03:54
by lexikos
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

// 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.

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

Posted: 19 Jul 2017, 16:06
by coffee
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

// 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.