Why this assign line no works?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Archimede
Posts: 503
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Why this assign line no works?

Post by Archimede » 02 Jun 2023, 05:09

Hallo.
Why this line works:
sText := "; "
and this generates error:
sText := "; ;"
?

gregster
Posts: 9014
Joined: 30 Sep 2013, 06:48

Re: Why this assign line no works?

Post by gregster » 02 Jun 2023, 05:20

Because a ; with a space or tab in front starts an inline comment. At script start, the interpreter removes all comments from the script version in memory that it will actually run. Try instead to escape the ; :

Code: Select all

sText := "; `;"

Archimede
Posts: 503
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Why this assign line no works?

Post by Archimede » 02 Jun 2023, 05:28

But
";"
is not
;
in front! Then it is not a comment...

gregster
Posts: 9014
Joined: 30 Sep 2013, 06:48

Re: Why this assign line no works?

Post by gregster » 02 Jun 2023, 05:31

gregster wrote:
02 Jun 2023, 05:20
a ; with a space or tab in front starts an inline comment.
https://www.autohotkey.com/docs/v1/Language.htm#comments wrote:Scripts can be commented by using a semicolon at the beginning of a line. For example:

; This entire line is a comment.
Comments may also be added at the end of a line, in which case the semicolon must have at least one space or tab to its left. For example:

Run Notepad ; This is a comment on the same line as a command.
[...]
Since comments are ignored when a script is launched, they do not impact performance or memory utilization.

wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Why this assign line no works?

Post by wetware05 » 02 Jun 2023, 07:52

Hi

Programming languages ​​are based on rules and at the same time on the hierarchy of such rules, where the secondary ones have to abide by the superior ones in the hierarchy. Said rules do not have to be logical outside of their own language. It may even seem counter-intuitive (or stupid), without understanding such rules and their hierarchies.

Archimede, has found one of those paradoxes.

The language of programming has the same meaning as politics or a religion: from the outside —the non-learned or non-"believer"—it seems to make no sense. The same for the customs of each culture.

gregster
Posts: 9014
Joined: 30 Sep 2013, 06:48

Re: Why this assign line no works?

Post by gregster » 02 Jun 2023, 08:10

It's a simple rule.
Consider:

Code: Select all

msgbox hello ; covfefe
How should AHK decide if ; covfefe is part of the msgbox text or an inline comment? It simply follows the language rules, in an order determined by a known algorithm.
The human user can do the same, and if they decide that it should be part of the message, they can use the documented AHK escape procedure.

If you use a code box, you already get a visual hint:

Code: Select all

sText := "; ;"
sText := "; `;"
(That doesn't mean that code boxes work perfectly - but here it could help to understand the problem. A good code editor, with working AHK syntax rules, can show you the same.)

Post Reply

Return to “Ask for Help (v1)”