Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3286
  • Last Modified:

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


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.  :)

  • 3
2 Solutions
Joe Winograd, Fellow&MVEDeveloperCommented:
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
Joe Winograd, Fellow&MVEDeveloperCommented:
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
Steve_BradyAuthor Commented:
Thanks Joe
Joe Winograd, Fellow&MVEDeveloperCommented:
You're welcome, Steve. Happy to help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now