I suggest to reserve return, break and continue only and do not allow (x(), break).
Only those 3 should be supported in if x, y(), return z, everything else must be an expression.
[Wish] One line while loop (similar to if)
Re: [Wish] One line while loop (similar to if)
That perl approach seems a bit backwards to me for putting the while and if toward the back, which isn't what happens in the non-one liners. I can see until being done like that though.jethrow wrote:I agree. I'm gonna go out on a limb & say it's because of the restrictions on how you can write your syntax (not un-similar to complaints against python). I don't want to add another line to my code - I want the simple condition & action on the same line - especially if I'm in a One-Liner type of mood. This becomes extremely important when I'm trying to write beautiful, condensed code - or just trying to impress others with my sophisticated coding skills.lexikos wrote:I really doubt that it's about there being less typing, either way.
... of course I'm being sarcastic, yet truthful ...
Anyways, I'm gonna jump the gun & say why not take the perl approach and allow:Code: Select all
action if conditon ; or action while condition
Re: [Wish] One line while loop (similar to if)
I may not be understanding, but I think what you've outlined above is useful (at least for me) just by itself, without any grouping functionality. I think, currently, all of these commands support a single unblocked statement immediately following the line (e.g., if you want to omit the braces), right? In that case, if I just want to use a single line with no braces I already can't have multiple statements on that line. I can have multiple assignments/expressions, but not multiple statements, correct? Even so, I use this no-braces option all the time for simple constructs. Isn't this proposal then just allowing that line to be moved up to the same line as the while, with all the same restrictions that would be there if this were a one-liner (unbraced) block?lexikos wrote: Implementing the following is trivial:It is less trivial to intuitively group the statements, as in if x, y(), return z grouping the last two in a block (or likewise when below an if/loop/etc.).Code: Select all
while condition, statement for var in expression, statement for var1, var2 in expression, statement expression, statement ; as in: x(), return y ; even: if x, y(), else, z()
For me, it would help a lot. I have lots of terse utility functions that are not that complicated to understand, and for these, compact is better. So, for example, ...
Code: Select all
while count<=max, execute(count++)
;is better (for me) than
while count<=max
execute(count++)
;the extra line doesn't really help things that much if the construct is simple.
Re: [Wish] One line while loop (similar to if)
Being "useful" isn't enough. AutoHotkey v1 is already useful as it is. v2 is not about making the language more useful. A large part of it is about eliminating sources of confusion. Some of these sources of confusion are special rules within the language which were intended to make it more useful but end up creating inconsistency, like x := 1, y = 2 allowing = to assign an expression.
If if x, y(), return z was interpreted asthat would be a source of confusion. The grouping problem is specific to expression, statement, which would be one way of allowing if condition, expression, else, statement. Obviously, the others could be allowed without this.
Allowing expression, statement but not SomeCommand, % expression, statement could be another source of confusion. Allowing the latter - with restrictions like "must be after the last parameter of the command" - would create more complication (harder to understand, remember, implement...).
In C-like languages, the return in if (x) y(); return z; does not belong to the if, but in those languages, the semicolon is clearly a statement separator, never used to delimit parameters or sub-expressions. In AutoHotkey, if x (newline) y(), z() works just fine because y(), z() is a single expression with the comma ("multi-statement") operator. But if expression, statement was allowed and simply treated as two separate lines (no block/grouping), either y(), return z() and y(), z() would be inconsistent, or worse, if x, y(), z() would be interpreted as
Allowing catch, var, statement would create another source of confusion, because someone is bound to write something like catch, return, where return is a variable intended as a statement.
In this case, the "usefulness" is subjective, and I think probably not in favour of the "non-programmers" who are ostensibly the main target of AutoHotkey.
If if x, y(), return z was interpreted as
Code: Select all
if x
y()
return z
Allowing expression, statement but not SomeCommand, % expression, statement could be another source of confusion. Allowing the latter - with restrictions like "must be after the last parameter of the command" - would create more complication (harder to understand, remember, implement...).
In C-like languages, the return in if (x) y(); return z; does not belong to the if, but in those languages, the semicolon is clearly a statement separator, never used to delimit parameters or sub-expressions. In AutoHotkey, if x (newline) y(), z() works just fine because y(), z() is a single expression with the comma ("multi-statement") operator. But if expression, statement was allowed and simply treated as two separate lines (no block/grouping), either y(), return z() and y(), z() would be inconsistent, or worse, if x, y(), z() would be interpreted as
Code: Select all
if x
y() ; conditional upon x
z() ; unconditional
In this case, the "usefulness" is subjective, and I think probably not in favour of the "non-programmers" who are ostensibly the main target of AutoHotkey.
Re: [Wish] One line while loop (similar to if)
I always wanted the option to write loops on one line, too. It would help me organize my code better, and for me, at least, to read it more easily, especially for short loops like what fincs offered as an example above.
My Stuff: mousey; volume; ahkinfo; instantbirder; npp highlighter; Dynamic File Menu; tv - a treeview library;
Re: [Wish] One line while loop (similar to if)
In many sources We see next style:Same-line syntax prevent further editing of script and made source less readable.
In other case parsing become more complicated.Same-line but what will be the result?OROR
Removing same-line in IF syntax separate expressions from actions by default.
Code: Select all
if (expression) {
oneonlyline();
}
In other case parsing become more complicated.
Code: Select all
if expressinon1, expression2, action1, action2
Code: Select all
if(expression1, expression2)
action1, action2 ;same-line 2 actions
Code: Select all
if(expressinon1, expression2, action1, action2)
"" ; the action
Code: Select all
if(expressinon1)
expression2, action1, action2 ;same-line 3 actions
AHKv2.0 alpha forever.
Return to “AutoHotkey Development”
Who is online
Users browsing this forum: OpalMonkey and 69 guests