a080: same-line if parsing error

Discuss the future of the AutoHotkey language
sirksel
Posts: 222
Joined: 12 Nov 2013, 23:48

a080: same-line if parsing error

14 Jun 2017, 07:56

Lexikos, did you change the way same-line if works in a080? For example:

Code: Select all

if t[idx]==na,  (t[idx]:=dft,  qty++)
used to work fine, and it seems like it still follows the syntax rules I read. I was under the impression that multi-expression, especially when in parens, could be used anywhere a normal expression could be used. I now get a parsing error. Is this a special case? The specific error I get is: "If" accepts at most 2 parameters.

Thanks again for all the time you put into the latest changes. It was a huge number of commits, and lots of big decisions you made -- which I'm sure you deliberated/debated for some time.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: a080: same-line if parsing error

14 Jun 2017, 22:35

I did not change the way same-line if works; it does not work at all.

I had planned to make a decision on whether to remove it or add same-line actions for other control flow statements (where possible). I was most likely going to decide to remove it, so don't expect to see it fixed.
I was under the impression that multi-expression, especially when in parens, could be used anywhere a normal expression could be used. I now get a parsing error. Is this a special case?
No. It was a special case, but now it's the same as every other control flow statement and function-call-without-parentheses.

Within a parameter list (and not enclosed in (), [] or {}), comma always delimits parameters. With the old way of interpreting commas, the last parameter would appear to get pushed to the end, with unused parameters in between. For example, MsgBox Text, Title, IGNORED, Options, or MsgBox Text, Title, IGNORED, IGNORED, Options, because it would be interpreted as MsgBox Text, Title, (IGNORED, IGNORED, Options). (But the v1 and v2 multi-statement operators differ.)

It is not true that multi-statement comma could be used anywhere a normal expression could be used. Any expression can contain a multi-statement expression in parentheses, but outside of that comma had multiple meanings and was not always part of the expression. For instance, in previous alpha builds, if condition, action was not multi-statement comma, because action was not part of the condition, and could be any statement, not necessarily an expression.

Using comma for this purpose seemed better (more intuitive) than the v1 way, which was to interpret if x, y as a multi-statement expression. With If (or If, While, and maybe others) being the only place a comma can be followed by any statement (vs. only an expression), it seems like one of those "special rules" that do more harm than good.

You can still do

Code: Select all

if (t[idx]==na,  (t[idx]:=dft,  qty++))  ; One multi-statement expression (the final condition is 'qty++')
; or
if t[idx]==na  ; One normal expression
    t[idx]:=dft,  qty++  ; One multi-statement expression (parentheses also allowed)
; or
(t[idx]==na) && (t[idx]:=dft,  qty++)
(t[idx]==na) ? (t[idx]:=dft,  qty++) : 0
sirksel
Posts: 222
Joined: 12 Nov 2013, 23:48

Re: a080: same-line if parsing error

15 Jun 2017, 12:09

Thanks for the clarification -- that helps a lot. One quick follow-up point... Of the examples at the end of your response, the last three have the desired effect, but the first one has a different effect, correct? Maybe that's what you meant by "the final condition is 'qty++'". In other words, the execution of the (t[idx]:=dft, qty++) isn't really conditional on t[idx]==na. Or am I missing something?

Also, one other quick follow-up question... when the error message says "If" accepts at most 2 parameters, what is the second of the two parameters it is referring to? The first parameter is the condition, but if I'm understanding your explanation correctly, a second parameter is not allowed, right?
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: a080: same-line if parsing error

15 Jun 2017, 19:31

Correct.

The second parameter is the same-line action. You get an erroneous error message because I have not removed the same-line action yet, merely broken it.

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: MiM and 26 guests