Trying to understand the colon equals (:=) symbol, especially in AutoHotkey (AHK)

Posted on 2014-02-13
Last Modified: 2014-02-28

I frequently use a scripting language called AutoHotkey (AHK) for creating macros. There's one particular symbol (:=) which, despite my going through the documentation on a number of occasions and asking questions in the AHK form, is just not clicking.

I've seen a few comments elsewhere indicating this symbol is used in some programming languages (and occasionally in math) but I don't know if it has the same meaning. Nevertheless, I'm posting the topic on EE now in hopes that someone might be able to provide some type of explanation or analogy — maybe from a different perspective — which will enable me to grasp the concept. By the way, I have no programming background but I do feel comfortable with Excel functions & equations (not VBA, but just the in-cell functions) as well as math (up through calculus) formulas and equations. Are there relationships or syntax in either of those areas which are analogous?

Following (between the dotted lines) are some comments which were provided by one (very patient) person on the AHK forum. Included is a quotation (in italics) from the AHK docs. (The script examples are part of the docs quotation.)

"[[AHK] Variables and Expressions is] a good page for an explanation of expressions vs variables. I find this bit especially useful:

"Storing values in variables: To store a string or number in a variable, there are two methods: traditional and expression. The traditional method uses the equal sign operator (=) to assign unquoted literal strings or variables enclosed in percent signs. For example:

MyNumber = 123
MyString = This is a literal string.
CopyOfVar = %Var%  ; With the = operator, percent signs are required to retrieve a variable's contents.

Open in new window

"By contrast, the expression method uses the colon-equal operator (:=) to store numbers, quoted strings, and other types of expressions. The following examples are functionally identical to the previous ones:

MyNumber := 123
MyString := "This is a literal string."
CopyOfVar := Var  ; Unlike its counterpart in the previous section, percent signs are not used with the := operator.

Open in new window

"The latter method is preferred by many due to its greater clarity, and because it supports an expression syntax nearly identical to that in many other languages.

"Expressions are especially useful because they are required to do math and are used in function parameters."

Another link which may be helpful is here: Var := expression

By the way, I don't know if this sort of cross-forum pollination is "legal" but I figure the more comments I can get, the better chance I have of getting it.  :)

Question by:Steve_Brady
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 54

Assisted Solution

by:Joe Winograd, EE MVE 2015&2016
Joe Winograd, EE MVE 2015&2016 earned 500 total points
ID: 39858190
I haven't read your whole post yet, which I will do a little later, but when I saw AutoHotkey (my favorite programming/scripting language these days), I wanted to fire off a quick response for you. The ":=" means to assign a value to a variable. The variable getting a value assigned to it is on the left of the ":=". The value being assigned is on the right, which could be as simple as an integer, or it could be a complex expression. For example, to set a counter to zero, here's a very common line of code:


To increase a counter by one, here's another very common line of code:


This quick note may be far too simplistic for you, so I'll read your full question more thoroughly later and will respond accordingly.

Btw, you may not know this (I didn't until a few days ago), but a new community was recently established to move the language forward. The latest release at the new community has a Windows installer, an offline help file, and a compiler that turns the AHK source code (plain text) into a stand-alone/no-install executable (an EXE file).

There is excellent documentation:

...including an alphabetical command and function index:

...a good tutorial:

...and an active user forum:

Regards, Joe
LVL 54

Accepted Solution

Joe Winograd, EE MVE 2015&2016 earned 500 total points
ID: 39858358
Now that I've read your whole post, my previous answer stands, with a few additions. First, I agree strongly with the "greater clarity" comment. Another good example of "greater clarity" is:


The above two statements produce the same result in AHK, but I much prefer the clarity of the first one.

To distinguish between the assignment operator and the Boolean "=" operator, many languages chose ":=" as the assignment operator, including Algol and Pascal. AHK managed to find a way to use both ":=" and "=" for assignments, providing some flexibility, but also some confusion to go along with it.

AHK is a great language, but has some quirks, one of which relates to the assignment operators. When parameters are fed into an AHK program, they come into variables called %1%, %2%, %3%, etc. When params come into an AHK program, I like to assign them to variables with meaningful names. So the first time I did this in an AHK script, I had these statements:


Guess what? Didn't work! The syntax in this case must be:


This is no doubt because of the percent signs around the param variables, in which case AHK wants the "=" assignment operator, not the ":=" one. There are some other rare circumstances where I go with "=" for assignment, but in nearly all cases, it's ":=". For example, take a look at the AHK program in this EE article and you'll see my heavy-duty use of ":=" as the assignment operator. Regards, Joe

Author Closing Comment

ID: 39896377
Thanks Joe
LVL 54

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 39896381
You're welcome, Steve. Happy to help.

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question