Basic operation confused Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Basic operation confused

16 Mar 2019, 21:38

Can I find any directly related explanations from the HELP file ? for case3 and case4 ?
Especially for case6, I am totally lost.

Thanks

Code: Select all

x := 1
y := 23
a := "1"
b := "23"
MsgBox % ""
.  "case1  " x + y "`n"			; 24 
.  "case2  " x - y "`n"			; -22 
.  "case3  " a + b "`n"			; 24    ??  could be. but, I guess, it is wrong. Should be "123"
.  "case4  " a - b "`n"			; -22   ??  
.  "case5  " "1" + "23" "`n"	; "123" 
.  "case6  " "1" - "23" "`n"	; 1     ??  "1" ? something else ?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Basic operation confused  Topic is solved

17 Mar 2019, 05:19

For historical reasons, quoted numeric strings such as "123" are always considered non-numeric when used directly in an expression (but not when stored in a variable or returned by a function). This non-numeric attribute is propagated by concatenation, so expressions like "0x" n also produce a non-numeric value (even when n contains valid hexadecimal digits). This problem can be avoided by assigning the value to a variable or passing it through a function like Round(). Scripts should avoid using quote marks around literal numbers, as the behavior may change in a future version.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Basic operation confused

17 Mar 2019, 07:18

thanks for good info

yes History explains that all.

I have tested all the definitions of dot symbol usage as a concatenate operator and concluded that usage could be removed.
But, as I said, it is just a tiny bit corner of its history. So, nobody can change it and no needed to change it.

Regards
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Basic operation confused

17 Mar 2019, 07:38

ah
the case6 is an error, silent error, nothing else.
thanks to the error, it has only the good part "1" (just before the erroneous minus operation part).
-Of course I have failed to find any kind of hard definition of this operation, I just guessing it.
-in the same sense, there is no definition of case5 too

Regards

[EDIT] I have found it at Unary minus operator explanation. Thanks, Helgef
Last edited by IMEime on 18 Mar 2019, 02:34, edited 1 time in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Basic operation confused

18 Mar 2019, 01:36

Code: Select all

"case3  " a + b "`n"			; 24    ??  could be. but, I guess, it is wrong. Should be "123"
Certainly not, + is not used to concatenate strings. Again,
This problem can be avoided by assigning the value to a variable
and
General Conventions wrote:No typed variables: Variables have no explicitly defined type; instead, a value of any type can be stored in any variable (excluding built-in variables). Numbers may be automatically converted to strings (text) and vice versa, depending on the situation.

For case 6, the reason only the good part is left is because, since the - is preceded by a quoted string, it cannot be binary minus (i.e., substraction), so it must be unary minus, hence the following quoted string yields an error,
Expression wrote:Except where noted below, any blank value (empty string) or non-numeric value involved in a math operation is not assumed to be zero. Instead, it is treated as an error, which causes that part of the expression to evaluate to an empty string

For case 5, now it is unary plus since the preceding operand is a quoted string, but
Unary minus wrote:On a related note, any unary plus signs (+) within an expression are ignored.
so there is no error since it the unary plus is ignored. Hence the concatenation.

Cheers.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Basic operation confused

18 Mar 2019, 02:27

Thanks
Good info and nice explanations

I'm having a good time to read HELP document carefully
Should I have any questions again I will be back

Regards

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Joey5, justcop, Rohwedder and 176 guests