AutoHotkey v2 Syntax change proposal.

Discuss the future of the AutoHotkey language
vasili111
Posts: 747
Joined: 21 Jan 2014, 02:04
Location: Georgia

AutoHotkey v2 Syntax change proposal.

16 Feb 2014, 06:20

Evaluate and add to variable:

Current syntax

Code: Select all

variable := 5+5
variable3 := variable1 + variable2
Proposed syntax

Code: Select all

variable = 5+5
variable3 = variable1 + variable2
Add to variable as is, dont evaluate:
Current syntax

Code: Select all

variable = 5+5
Proposed syntax

Code: Select all

variable = "5+5"
So in proposed syntax, for evaluation and after adding to variables we use = sign. For differentiation from adding text to variable as is without evaluation, we need to include text in quotation sign "" , like here "Sometext here". We need also to use here escape character, I think \ is good for it. Everything in quotation sign "" is not evaluated and is treated as a string except character after escape character! For example to add string "Some text here" (here quotation marks are part of the string) to variable:

Proposed syntax:

Code: Select all

stringvar = "\"Some text\""


String concatenation:
Proposed syntax:

Code: Select all

variable1 = "Text 1, "
variable2 = "Text 2"
variable3 = variable1 + variable2
So here we concatenate string in variable1 to variable2 and put the result in variable3. So variable3 value will be string (without quotation marks) "Text 1, Text 2".


Variable and text differentiation:
Current syntax:

Code: Select all

msgbox, Some text %variable% 
;or use %
msgbox, % "Some text " variable

Proposed syntax:

Code: Select all

msgbox, "Some text " + variable
msgbox, "Some text " + array[1]
Currently we use % for variables, like this %variable%, in some commands to differentiate it from text, but we use variables in math operations without any mark. New syntax allows to use everywhere variables without any special marks. Also in proposed syntax we treat array items as variables.
Here we use plus sign + as concatenation sign. In case where something is added to a string plus sign is becoming concatenation sign and every variable is treated as string value and one string is added to another.


Boolean operations:
Current syntax:

Code: Select all

variable2:= variable1 + 5
if (variable2 = variable3)
{
     ;some code
}
Proposed syntax:

Code: Select all

if (variable1 + 5 == variable3)
{
     ;some code
}
So we use == instead of = in conditions. This makes possible to write math expressions in condition and dont make variable that we dont need. Also if we use in conditions == instead of = , I think it will be better to use <== instead of <= , use ==> instead of => , use !== instead of != .


Summary
1) After implementing all of this we will be able to use variables everywhere without %.
2) We need to include all strings in "" , like this "Here is some text"
3) We will be able to concatenate strings.
4) We will be able to use expressions in conditions and avoid using unnecessary variables.
5) := sign is not needed anymore.

Similar syntax is used in JavaScript.
Last edited by vasili111 on 16 Feb 2014, 13:48, edited 2 times in total.
DRAKON-AutoHotkey: Visual programming for AutoHotkey.
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: AutoHotkey v2 Syntax change proposal.

16 Feb 2014, 11:46

We need also to use here escape character, I think \ is good for it. Everything in quotation sign is not evaluated and is treated as a string except character after escape character!
As I understand it, quote mechanics have already been changed. You may use " or ' as long as the string starts and ends with the same mark. Note this is not unprecedented and has already been used in languages such as Python. For example this Python code:

Code: Select all

print "Hello World"
print 'Hello World'
print "A string with a 'quote' inside"
print 'A string with a "quote" inside'
would produce this output:

Code: Select all

Hello World
Hello World
A string with a 'quote' inside
A string with a "quote" inside
I would also be against \ as an escape character, simply because it gets confusing with file paths...

Code: Select all

C:\\Program Files\\AutoHotkey
And would the result of this be 10 or 55? How would you obtain the opposite result if that was desired?

Code: Select all

variable1 = "5"
variable2 = "5"
variable3 = variable1 + variable2
vasili111
Posts: 747
Joined: 21 Jan 2014, 02:04
Location: Georgia

Re: AutoHotkey v2 Syntax change proposal.

16 Feb 2014, 13:46

LinearSpoon wrote:As I understand it, quote mechanics have already been changed. You may use " or ' as long as the string starts and ends with the same mark. Note this is not unprecedented and has already been used in languages such as Python.
Now in AutoHotkey if you write variable = "Some text" you will have in variable stored string "Some text"
Now in AutoHotkey if you write variable := "Some text" you will have in variable stored string Some text

In proposed syntax there will be only one form to store string in variable variable = "Some text" and we will have in variable stored string Some text . This new syntax makes possible to point the interpreter that everywhere, where it finds a text in "" it is string. Also everywhere where it finds text without "" and it is not a function it is varriable. This makes possible to eliminate necessity of using % with variables which now it is needed in some cases. Also we will not need to use anymore := sign.


LinearSpoon wrote:I would also be against \ as an escape character, simply because it gets confusing with file paths...

Code: Select all

C:\\Program Files\\AutoHotkey
I think you are right. AutoHotkey for automation purposes frequently needs to use file or folder path. So it is good idea to use different escape sign. We can use for it ` sign (I did not remember its name, it is under escape button of keyboard, it is not ' sign).


LinearSpoon wrote:And would the result of this be 10 or 55? How would you obtain the opposite result if that was desired?

Code: Select all

variable1 = "5"
variable2 = "5"
variable3 = variable1 + variable2
In proposed syntax if we are assigning value which is inside "" signs, we telling interpreter that the variable strings. In proposed syntax + sign used with strings is for concatenation not for mathematical addition. So in your example with using proposed syntax variable variable3 value is 55.

In proposed syntax:

Code: Select all

variable1 = 5
variable2 = 5
variable3 = variable1 + variable2
Now value of variable3 is 10
DRAKON-AutoHotkey: Visual programming for AutoHotkey.
User avatar
LinearSpoon
Posts: 156
Joined: 29 Sep 2013, 22:55

Re: AutoHotkey v2 Syntax change proposal.

16 Feb 2014, 17:07

I did not mean that the quotation changes were in the current AutoHotkey 1.1, but that it was already a change made in V2 and listed on V2 changes (First item under Expressions).
v2-changes wrote:Quoted literal strings can be written with "double" or 'single' quote marks, but must begin and end with the same mark. Both allow nested expressions such as "Next year is %A_Year+1%". Literal quote marks are written by preceding the mark with an escape character - `" or `' - or by using the opposite type of quote mark: '"42" is the answer'. Doubling the quote marks has no special meaning, and causes an error since auto-concat requires a space.
About the proposed concatenation example: Perhaps I was too subtle. I only meant to suggest there should be two separate operators, one for addition and one for concatenation.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: AutoHotkey v2 Syntax change proposal.

16 Feb 2014, 20:03

So to summarize, you want:
  • = instead of :=
  • == instead of =
  • \ as escape character instead of ` (quote marks can be escaped this way only in v2)
  • Commands to accept expressions by default
  • + for concatenation
Those things have all been considered already and rejected long ago. For the most part, there's insufficient reason to change these things. For + concat, consider the fact that numbers are often stored as strings.
vasili111 wrote:So we use == instead of = in conditions. This makes possible to write math expressions in condition and dont make variable that we dont need.
That's already possible in v1 and v2. You can even use == if you like...
In proposed syntax there will be only one form to store string in variable
That's already the case in v2: var := "string".
This makes possible to eliminate necessity of using % with variables which now it is needed in some cases.
It's already possible to avoid % for variables.
User avatar
joedf
Posts: 8953
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: AutoHotkey v2 Syntax change proposal.

19 Feb 2014, 14:54

i thought it was..
:= instead of =
use = & == for if ...???
or remove = completely... hmm oh well.. this has been discussed a "begillion" times..
Ill go with whatever comes... all i know is that the = vs == issue will resolved.
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: AutoHotkey v2 Syntax change proposal.

19 Feb 2014, 17:41

joedf, that is neither what vasili111 is proposing nor what has already been decided and implemented for v2.

:= is not instead of =; the legacy = assignment has simply been removed and := is the same as before.
IF already used = and == and still does, but defaults to an expression even without parentheses.
User avatar
joedf
Posts: 8953
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: AutoHotkey v2 Syntax change proposal.

19 Feb 2014, 18:10

Oh ok, I see. Thanks for the clarification.
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: AutoHotkey v2 Syntax change proposal.

11 Mar 2014, 11:13

Comparison signs <=, >=, !=, ==, <> MUST be different from assignment sign (I prefer := ).
:= is a PASCAL sign but fits to other C assignment signs +=, -=, /=, *=, etc.
AHKv2.0 alpha forever.
Zelio
Posts: 278
Joined: 30 Sep 2013, 00:45
Location: France

Re: AutoHotkey v2 Syntax change proposal.

12 Mar 2014, 05:44

I don't know where to post... just some thoughts as usual... half is already implemented in version 2...
= for permissive equality, case insentitive string comparison, numbers rounded to a 15 digits string to avoid current float problems (only exclude the ending when compare).
== for strict equality, case sentitive string comparison, normal binary floating-point comparison (best performance here).
"= or '= or `= or ;= for string assignment (first one is the best, same symbol). Also it can be used like a string to append...
ninmonkey
Posts: 8
Joined: 13 Dec 2013, 16:02

Re: AutoHotkey v2 Syntax change proposal.

24 Mar 2014, 11:01

I would absolutely love the removal of non-expression statements. Coming from other programming languages, that's confusing to deal with.

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 68 guests