Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Gathering ideas for AutoHotkey v.2


  • Please log in to reply
126 replies to this topic
PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Disclaimer: this first message isn't official, ie. it comes from me, not from Chris.
So it expresses only ideas I have on what this v.2 should be, although I believe some of the ideas here were expressed by Chris (or others).
This topic is open for discussion, of course.

First, a bit of history, it might help to understand the need for a v.2.
In prehistoric times, there were AutoIt 2, a scripting language for Windows whose syntax was more or less batch-like, setting values in the environment to manage "variables", having only the most primitive operations (Add, Sub, Mult, Div), with a rigid syntax (easy to parse) of command followed by parameters.
To do more complex computations, you had to use an external program!
Then, Chris created AutoHotkey based on AutoIt 2 syntax, to keep a compatibility with hundred of scripts, compatibility that was dropped by the AutoIt team.
The above limitations being annoying, he improved the syntax, introducing expressions.
To keep compatibility, he made a second syntax, using := to assign the result of an expression, and parenthesis around the condition of an If to evaluate it like an expression (with annoying exceptions...).
It was a good thing, but with time, it proved to be very confusing to newbies, that wrote stuff like:
a = b * (c - d)
x = %y% + %z%
If val = var - 1
If (%a% = %b%)
and so on...

So, one of the main motivation for the v.2 is, AFAIK, to simplify and make consistent this syntax, at the cost of dropping the original compatibility with AutoIt 2.
Note that the later isn't any more a must have, old AutoIt 2 scripts are probably long forgotten and obsolete, and the number of AutoHotkey scripts is probably much bigger!

Some people fantasied and proposed more changes, so AHK would look more like their favorite programming language (often JavaScript...).
Chris made clear that he wants to keep the changes to a minimum, to avoid unnecessary fluff and to keep the original flavor of AHK.
Other people seems to find AutoHotkey easy to learn and to use due to old syntax, ie. lack of quotes around strings, of parentheses around command arguments, etc.

So let's try to walk the thin line between those opposed goals.
Note I propose NOT to discuss here major new features, like improvement of API structure support or true arrays, as they already have their own topics.

So, let see these two tripping syntax differences.

Following Chris (IIRC), I propose that in v.2, = acts like :=, ie. it expects an expression on the right.
So a = It's cool would generate a syntax error message.
Perhaps := would be kept as is, to ease the transition, but discouraged.
Now, I believe we should keep literal assignment, as it is convenient, and I like the dereferencing.
To avoid any ambiguity, it could have a very different symbol, so there would be no ambiguity by using it.
I propose to use <<. It is graphically explicit, and would please Unix (and perhaps Dos) users, and C++ programmers too (stream-like syntax...).
a <<  ; Set var to be empty
s << Quickly set a long string (auto-trimmed)
%refToVar% << Result: %res%`n(%nb% lines)
I propose that, since there is no ambiguity at all (no command possible on the same line), that If is always followed by an expression, even if there is no parentheses.
If a = y - x
If bCond1 and (bx or by)
If foo >= bar {  ; For those liking the OTB
If (c >= 0x41 && c <= 0x61) ; Parentheses can be there in all cases
Making the parentheses optional is, I believe, in the spirit of AHK, by not forcing to use symbols that are not needed. Simpler, faster to type, flexible.

Other points that have been discussed:

- Drop the obsolete convention that space is a concatenation symbol in expressions. Let the space-dot-space be the official and only symbol. Here again, too much possibilities are confusing, and the old convention proved to bring ambiguity and bugs.

- A symbol to allow to allow putting several commands on the same line.
It is not obvious, because lot of commands take a "naked" string as last parameter, and such a string can end with any symbols. So I proposed to allow such separator only to separate expressions. And Chris proposed to use the comma to this end.
This is a good idea: it has already a special meaning as separator, has no meaning in expressions, and is separator in C/C++ too.

- Make deprecated a number of commands that proved to be unused by most people, of obscure meaning, or that have been obsoleted by expressions.
They would live in some versions, then would dissappear. That would make the binary smaller, the manual lighter and less intimidating. In the interim phase, they would be banished in common purgatory page, so curious people could still find them if meet in a script, but the manual would be still simplified.
No exhaustive list yet, but good candidates are the compound If (IfEqual, IfNotEqual, ...), the primitive operations (EnvAdd, EnvSub, ..., retaining the special += and += seconds), some directives changing behavior of scripts, most Transform commands which are replaced by functions, etc.

I would like also to remind an old wish: to concatenate strings to the end of a variable, a very common operation.
var .= result . "`n"
res <<< result`n
OK, that's all for now, but I might come back to augment this list, and you can, too!
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006

Drop the obsolete convention that space is a concatenation symbol in expressions. Let the space-dot-space be the official and only symbol. Here again, too much possibilities are confusing, and the old
convention proved to bring ambiguity and bugs.

I think that space is more convienient then dot. So can you tell me more about those problems related to it ?

So I proposed to allow such separator only to separate expressions

I would like to see full separator. Especially with proposed <<
for witch it can be made not to work, and to act like a regular symbol. U don't put much naked strings in other cases and if = finish as := it will be even less...


Other things seem nice to me.
Posted Image

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Thanks Philho,
The sugguestions you gave are very well thought through and I support these changes. I wouldn't hessitate to rewrite some of my codes to follow such a new syntax, since I see the benefit.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Thalon
  • Members
  • 641 posts
  • Last active: Jan 02 2017 12:17 PM
  • Joined: 12 Jul 2005
I like your ideas :)

I propose that, since there is no ambiguity at all (no command possible on the same line), that If is always followed by an expression, even if there is no parentheses.

If a = y - x
If bCond1 and (bx or by)
If foo >= bar {  ; For those likeing the OTB
If (c >= 0x41 && c <= 0x61) ; Parentheses can be there in all cases

So to compare with a String it would be
if foo = "bar"
?

Although a variable name may consist entirely of digits, this is generally used only for incoming command line parameters. Such numeric names cannot be used in expressions because they would be seen as numbers rather than variables.

Would it make sense to remove this (if possible)? This is another inconsistence some new users do not understand.
if (Var1 = 1 OR Var1 = "String")
If you set the quote-char around "1" it will not work without any shown reason or error.

Thalon

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

I think that space is more convienient then dot. So can you tell me more about those problems related to it ?

There is a bug report about this. In short, the following code doesn't work:
x = abc
y = fgh
MsgBox % &x " / " &y
and it might have other problems I don't precisely recall. And Chris see this notation as old and obsolete, and I agree. Too ambiguous in a language where everything is string...

I would like to see full separator. Especially with proposed << for witch it can be made not to work, and to act like a regular symbol. U don't put much naked strings in other cases and if = finish as := it will be even less...

Sorry, but I don't understand this remark (beside the first sentence). I don't see the relation with <<.

Which IIRC?

:?: IIRC = If I Recall Correctly... I tend to use these frequently used abbreviations, sorry (AFAIK, IMHO, etc.).

So to compare with a String it would be

if foo = "bar"
?

I wasn't too sure where your remark started, you forgot the quotes. I figured out. So, yes, If foo = "bar" will be the same as If "bar" = foo.

I agree also with your idea on the old convention of command line arguments: while we change the language, let's drop it.
One solution, if true arrays come in in time, is to put these arguments in an array, eg. A_CmdLineArg or something like that.

A note on <<. I forgot it was used in expressions, but there is no ambiguity, because it stands on a line of its own, not on the right of = or in a command or a function call.
Now, if this is confusing, we can use <- which is unambiguous and still explicit. I would avoid <= for example, first because it is also used in expressions, and because I want to avoid the use of =, to eliminate any ambiguity and confusion with expression assignment.

Thanks for the nice comments. Most of the ideas has been already discussed, so this is a collective work.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
There is a point I forgot to mention.
Although these changes will not be a revolution (like using another language), it will create lot of points of incompatibility. Chris plans to make a program or a script to automatically adjust v.1 scripts to the new v.2 rules.

But do we need to distinguish the old scripts from the new ones?

Should we keep the same extension? Of course, we can tweak the registry if we want to change this at our own level, but an official support would be better.
Should we have .ahk2 scripts? Or .ah2, if we absolutely want to stick to 3 letter extension? (No real need here.)

Likewise, perhaps we should create a new code tag (code2?) with distinct colors, so we can see at a glance which AHK is necessary to run it.
Otherwise, we will have lot of newbies complaining that a script found on the forum doesn't work with latest version of AutoHotkey!
Not sure that's such a hot idea, as lot of people will forget to use the new tag... Perhaps we need a separate forum!
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Thalon
  • Members
  • 641 posts
  • Last active: Jan 02 2017 12:17 PM
  • Joined: 12 Jul 2005
I added the quotes when rereading my post (before reading yours ^^) and came to the correct meaning of IIRC reading another english forum ;)

I think I would prefer to keep the old scripts under .AHK with old runtime and don't convert most of my scripts. So .AHK2 would be a good ending in my eyes...

Thalon

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Yes, a distinct extension would allow this: to have two runtimes.
It would avoid the chore of updating all old scripts, and to quickly test an old script from the forum, while new scripts would be written to target the new version.
And old scripts could be updated progressively, the change of extension allows to keep scripts in the same folder while seeing which ones are still to be converted.
Plus I already changed the Scintilla's lexer for AHK from ahk to ahk1, in provision for the v.2. Since SciTE mostly choose the lexer from the extension, we must have a way to distinguish them.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

foom
  • Members
  • 386 posts
  • Last active: Jul 04 2007 04:53 PM
  • Joined: 19 Apr 2006

Now, I believe we should keep literal assignment, as it is convenient, and I like the dereferencing.
To avoid any ambiguity, it could have a very different symbol, so there would be no ambiguity by using it.
I propose to use <<. It is graphically explicit, and would please Unix (and perhaps Dos) users, and C++ programmers too (stream-like syntax...).

I don't like the << because its the same as = in blue. In my opinion literal assignment should be banned completely. I don't understand why you all want to have this simple assignment when its the most ambiguous thing in ahk which leads to errors. Just changing the operators will not attenuate the problem of ahk and that is the lack of consistency. Which however is not only because of the assignment operators.
There are many special cases like
Loop, Parse, InputVar , CSV
If var in ,,1,2,3
literal quote:=""""
Escaping character is a farce in ahk because its just limited to string assignment and there is again an exception to ".
(Personal side-note: I hate the escape-char to be ` because on my German keyboard i need to press the accent key twice and backspace to get a single accent. When creating list delimited by a newline this is becoming a real pain in the arse) I mention this because now there is regexp and in regexp we have again an consistency issue with escaping some chars like newline and tab. There should be only one legal way.
Since \ is the escape character from many other very popular languages it should become the default escape-character because it will be easier to do a transition from or to other languages.
Same goes for strings. String should be clearly marked by enclosing them in quotes. If one would like to take it even one step further the options in commands could even be enclosed by quotes although i can live with the options of commands being threated as strings by default since most of the time evaluation operations aren't needed in commands options. However one could take this even one step further one more time and replace all commands with functions in which however options would have to be enclosed in quotes since they are passed as string to the function. But i don't like this idea since i appreciate that commands are much faster than functions in ahk.

Regarding the broken scripts issue i have a very easy solution. Create a new "Scripts And Functions" forum and rename the old "Scripts And functions" forum to "Old Scripts And Functions Archive". Creating a new topic in this forum should be disabled. One could look for scripts in this archive and ask if someone is willing to convert them to the new syntax by just replying to the related topic. Or if the developer of a script has converted his script to the new syntax he could edit his topic and redirect to the new "Scripts And Function" forum where his new script resides.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005

(Personal side-note: I hate the escape-char to be ` because on my German keyboard i need to press the accent key twice and backspace to get a single accent. When creating list delimited by a newline this is becoming a real pain in the arse)

Personal reply: Type the accent once and hit the spacebar.

Edit: I'm not very fond of using a new extention. Although I can follow your arguments, I just doesn't feel right.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Thalon
  • Members
  • 641 posts
  • Last active: Jan 02 2017 12:17 PM
  • Joined: 12 Jul 2005

(Personal side-note: I hate the escape-char to be ` because on my German keyboard i need to press the accent key twice and backspace to get a single accent. When creating list delimited by a newline this is becoming a real pain in the arse)

Personal reply: Type the accent once and hit the spacebar.

Or press the accent once and write normal afterwards ;)
`k = Shift + Accent and a "k" afterwards...

don't like the << because its the same as = in blue.

Hmm.. it's not the same, because it is much more different to ":=" or "=", so it's marked as string as well as with quote-characters...

Thalon

JSLover
  • Members
  • 920 posts
  • Last active: Nov 02 2012 09:54 PM
  • Joined: 20 Dec 2004

I propose that, since there is no ambiguity at all (no command possible on the same line), that If is always followed by an expression, even if there is no parentheses.

...I don't care if if's require parens or not, but if they ARE there it needs to support commands on the same line...

;//work...
if a=y-x
	msgbox, works

;//work...
if (a=y-x)
	msgbox, works

;//fail...
if a=y-x msgbox, oops

;//work...
if (a=y-x) msgbox, yay
...& about this...

;//fail?...
if foo>=bar {  ; For those liking the OTB

;//work...
if (foo>=bar) {  ; For those liking the OTB

- Drop the obsolete convention that space is a concatenation symbol in expressions.

...no!!!...space-dot-space...1) looks dumb...2) is too much to type...I want + to be a concat operator...with no space around it...I h a t e s p a c e d o u t c o d e...it's hard to read...see...

Let the space-dot-space be the official and only symbol. Here again, too much possibilities are confusing, and the old convention proved to bring ambiguity and bugs.

...the "old" convention only had bugs in ONE obscure code snippet (that I think you posted)...that snippet could be fixed by either...1) using space-dot-space...2) using parens around the parts the needed eval'd 1st...

- A symbol to allow to allow putting several commands on the same line.

...semi-colon.

And Chris proposed to use the comma to this end.

...I still don't understand how comma can work, but I'm open (sorta) to examples...but semi-colon is better...either leave the comment char space-semi & make command sep be no-space-semi...or change the comment char to space-semi-semi & make the command sep be semi, space on either side or not...examples...

;//Proposal 1...
;//space-semi = comment
;//no-space-semi = command sep
a=1;b=2         ;comment
a=1; b=2        ;comment

;//Proposal 2...
;//space-semi-semi = comment
;//semi = command sep
a=1;b=2         ;;comment
a=1; b=2        ;;comment
a=1 ; b=2       ;;comment

;//Proposal 3...
;//3 or more spaces or 2 or more tabs = comment
;//semi = command sep
a=1;b=2         ;comment
a=1; b=2        ;comment
a=1 ; b=2       ;comment

I would like also to remind an old wish: to concatenate strings to the end of a variable, a very common operation.

...ok at 1st I didn't know what you meant, your pseudo-code was confusing...did you mean...

var="wow"
var=var "wee"
...in that case += should do strings too...

var="wow"
var+="wee"

I agree also with your idea on the old convention of command line arguments: while we change the language, let's drop it.

...we have to drop it...since expressions see numbers as numbers, we won't be able to access them once = means :=...

One solution, if true arrays come in in time, is to put these arguments in an array, eg. A_CmdLineArg or something like that.

...I not sure why we need "true arrays" for this, I suggest built-in vars (that will become arrays once they exist)...

A_Params            Number of params
A_Param0            0th command line parameter...possibly same as A_ScriptName?...like
                    in batch files the 0th param is the name the program was called with
                    in uncompiled script this would be AutoHotkey.exe or possibly the
                    full path to the AutoHotkey.exe that ran it...(so I think this would be
                    different than A_ScriptName)...
A_Param1            1st param
A_Param2            2nd param
A_Param[color=red]N[/color]            [color=red]N[/color]th param
A_ParamsAll         All params from 1 to [color=red]N[/color]
A_CmdLine           Contents of GetCommandLine() API...only if different than what's available above
                    for example, this might include the 0th param, when A_ParamsAll wouldn't...

Should we keep the same extension?

...f*** yes...

Should we have .ahk2 scripts?

...f*** no...

Likewise, perhaps we should create a new code tag (code2?)

...what?...on the forum?...ok yes, but not code2...
[code=auto:0] = like it is now
[codescroll] = textarea or other scrollable box
[codehl] = code with highlighter (color)...or I can try to code some nice JavaScript to toggle different code styles...saving the last chosen or default to a cookie...then we only need one code tag...or perhaps the code tag used would specify what that post wants to default to, but clicking would still toggle...

Otherwise, we will have lot of newbies complaining that a script found on the forum doesn't work with latest version of AutoHotkey!

...ah, yes, those forever newbies...I propose a #Version directive...new scripts can say #Version 2...& when run on an old version it would complain...issue a new version 1 that understands this & rejects scripts declaring #Version 2...& version 2 would reject scripts...1) not declaring #Version 2 or declaring #Version 3...this could get more specific...for example #Version 1.0.45.03 & people would immediately know they need to update/downdate their AHK for that script...(I posted a RegEx script & they didn't have regex yet)...

Perhaps we need a separate forum!

...omg what?
Useful forum links: New content since: Last visitPast weekPast 2 weeks (links will show YOUR posts, not mine)

OMFG, the AutoHotkey forum is IP.board now (yuck!)...I may not be able to continue coming here (& I love AutoHotkey)...I liked phpBB, but not this...ugh...

Note...
I may not reply to any topics (specifically ones I was previously involved in), mostly cuz I can't find the ones I replied to, to continue helping, but also just cuz I can't stand the new forum...phpBB was soo perfect. This is 100% the opposite of "perfect".

I also semi-plan to start my own, phpBB-based AutoHotkey forum (or take over the old one, if he'll let me)
PM me if you're interested in a new phpBB-based forum (I need to know if anyone would use it)
How (or why) did they create the Neil Armstrong memorial site (neilarmstronginfo.com) BEFORE he died?

foom
  • Members
  • 386 posts
  • Last active: Jul 04 2007 04:53 PM
  • Joined: 19 Apr 2006

I forgot to mention that it sometimes gets pasted on a position you don't want it because it waits for the next character to see if it can modify it like è.

don't like the << because its the same as = in blue.

Hmm.. it's not the same, because it is much more different to ":=" or "=", so it's marked as string as well as with quote-characters...

It is the same. PhiLho suggestet to replace = by << because = is taking the place of :=.

Regarding the seperator. Why the heck isn't it changed completely like to $. This would eliminate the need of spaces around the dot. And the current implementation of concatenation is fubar. There are often post in the Ask For Help forum which are because of operations failing because of concatenation issues.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006

...the "old" convention only had bugs in ONE obscure code snippet

Yup, lover is right.

So if I have to choose between
a+b
a . b
a b

I chose the last one.

- A symbol to allow to allow putting several commands on the same line..
..semi-colon.

We already had discussion about this and ppl tend to stick with ; as comment. Don't want to discuss anymore this topic, but I think full command separation is needed.
If we stick to expressions only then, again, Python has a very nice thing for it:

PhilHo & others proposition is:
a=0, b=Func(x)
In Python you write:
a, b = 0, Func(x)
witch is very nice for some situations, like switch:
a, b = b, a
So, the imprtant thing to note here is that if naked strings are dropped (that is, if you can only specified strings between " ") then things we recently discussed about separators, comments etc musts be rediscussed with this new information since one of the bigest problem was litteral string occurance in the code. If this is changed we don't have this problem any more

...I don't care if if's require parens or not, but if they ARE there it needs to support commands on the same line...

reading my thoughts..

About number variables example like:
if 0<1
   MsgBox parameters not correct

should be killed as fast as can. I was very confused when I saw this...

...I not sure why we need "true arrays" for this

Your A_Param approach appears to me to be in AHK spirit, but that question is usualy done via array, so I support PhiLho here. If nothing else, it is good to follow "principle of last surprise" as parameteras are in array in countless number of languages.


About extensions, I think we should have single one and add new directive for it . As old scripts will fade away in time this is natural...
Posted Image

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

I don't like the << because its the same as = in blue. In my opinion literal assignment should be banned completely. I don't understand why you all want to have this simple assignment when its the most ambiguous thing in ahk which leads to errors.

I don't agree. It is ambiguous because people are used to use = to assign expressions. Making it distinctive should suppress this confusion while keeping a useful operator. I prefer to write:
a = %a%%val% values in %test%`n
; than
a := a . val . " values in " . test . "`n"
; and
a =
(
one
two
three
)
; instead of
a := "one`ntwo`nthree"
More readable, easier to maintain, avoid writing very long lines, avoid using the dreaded `...

(Personal side-note: I hate the escape-char to be ` because on my German keyboard i need to press the accent key twice and backspace to get a single accent. When creating list delimited by a newline this is becoming a real pain in the arse)

See my remark above for the list... And on French keyboard, I have to hit AltGr+(7|è) to get this char, and it is a dead key, needing another char after it (can be space). But if this other char isn't a vowel, it has no side effect. Actually, I just added ^²::Send ``%A_Space% to my permanent script for quick access... AHK provides the pain, but also the solution!

I mention this because now there is regexp and in regexp we have again an consistency issue with escaping some chars like newline and tab.

No, you can use `n and `r in a regular expression too.

Since \ is the escape character from many other very popular languages it should become the default escape-character because it will be easier to do a transition from or to other languages.

Very bad idea, it will make a pain to write Windows paths, regular expressions (all \ doubled like in Java, the horror!) and so on.

Regarding the broken scripts issue i have a very easy solution. Create a new "Scripts And Functions" forum and rename the old "Scripts And functions" forum to "Old Scripts And Functions Archive". Creating a new topic in this forum should be disabled.

There are also useful scripts in the Ask for Help section... And people might want to be able to still publish scripts for AHK 1.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")