Type mismatch. AutoHotkey_2.0-a096-2ad11cb

Discuss the future of the AutoHotkey language
_3D_
Posts: 176
Joined: 29 Jan 2014, 14:40

Type mismatch. AutoHotkey_2.0-a096-2ad11cb

14 May 2018, 05:10

Why?

Code: [Select all] [Download] GeSHi © Codebox Plus

;Gdip part
Screen:= ""

if ((Screen & 1) != "")
{
msgBox("Cool")
}
And in AutoHotkey_2.0-a096-2ad11cb

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Ok string not work with any arithmetic operators (+-*/&...) so code must be:

Code: [Select all] [Download] GeSHi © Codebox Plus

;Gdip part
Screen:= "100|200|5|7"

if (Screen is "number" && Screen & 1 != "")
{
msgBox("True")
}
else
{
msgBox("False")
}
Is that mean the v2 going to variable types?
AHKv2.0 use the future now.
_3D_
Posts: 176
Joined: 29 Jan 2014, 14:40

Re: Type mismatch. AutoHotkey_2.0-a096-2ad11cb

14 May 2018, 12:26

I think to be compatible "nonNumber" must return 0 and must be treated as 0 in expressions.
In Autohotkey "" is used to clear any type of variables so it must clear and "number" variables.
AHKv2.0 use the future now.
Helgef
Posts: 2990
Joined: 17 Jul 2016, 01:02
Contact:

Re: Type mismatch. AutoHotkey_2.0-a096-2ad11cb

14 May 2018, 13:22

If you clear your variable, you shouldn't use it in a math expression afterwards, luckily, we now get notified if we make such a mistake. This is the best thing that has happened to the language since sliced butter. Now, we only need var := "1" to behave the same way, that is, throw an exception in a math expression / function.

Cheers.
User avatar
nnnik
Posts: 2909
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Type mismatch. AutoHotkey_2.0-a096-2ad11cb

14 May 2018, 15:51

I dont think so.
Recommends AHK Studio
_3D_
Posts: 176
Joined: 29 Jan 2014, 14:40

Re: Type mismatch. AutoHotkey_2.0-a096-2ad11cb

14 May 2018, 22:58

In AHK no typed variables so in 100 lines code you can`t know what inside the variable to use it at math or no. And if there 5 variables we need 5 extra checks is "number".

Code: [Select all] [Download] GeSHi © Codebox Plus

number(arg){
return arg is "number"? arg: 0
}
I don`t understand why we need to throw exception instead of treated "nonnumber" as 0

Code: [Select all] [Download] GeSHi © Codebox Plus

;...
a:= b + 123
;...
Till now it was 123 if b == "" now exception ???

Exception make type separation: number - nonnumber, that is not in AHK style.
AHKv2.0 use the future now.
User avatar
nnnik
Posts: 2909
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Type mismatch. AutoHotkey_2.0-a096-2ad11cb

14 May 2018, 23:40

You need to adjust the way you write code for v2.
Disregarding Helgefs love for forcing explicit type conversions I think he's right about throwing an error on invalid math is a good thing.
Especially since you can use a try Statement to detect all errors.
Recommends AHK Studio
_3D_
Posts: 176
Joined: 29 Jan 2014, 14:40

Re: Type mismatch. AutoHotkey_2.0-a096-2ad11cb

15 May 2018, 10:18

nnnik wrote:You need to adjust the way you write code for v2.
Disregarding Helgefs love for forcing explicit type conversions I think he's right about throwing an error on invalid math is a good thing.
Especially since you can use a try Statement to detect all errors.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

As I said compatible.
AHKv2.0 use the future now.
guest3456
Posts: 2313
Joined: 09 Oct 2013, 10:31

Re: Type mismatch. AutoHotkey_2.0-a096-2ad11cb

15 May 2018, 10:33

_3D_ wrote:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

As I said compatible.


we are maintaining a v1/v2 compatible GDIP library here:
https://github.com/mmikeww/AHKv2-Gdip

this looks like one of the changes we need to make. this BitmapFromScreen() function allows the "Screen" param to either be:
1. "0" for all screens
2. "hwnd:" for a specific window
3. any number, for a specific monitor
4. "p|i|p|e" separated string for a specific screen area

this particular Screen&1 != "" seems to just be verifying case #3 above, that its a numbered of a screen. wouldnt just Screen is "number" be sufficient? and we can remove the bitwise-AND altogether? of course to be backwards compatible with v1 we'd do the same as this:
https://github.com/mmikeww/AHKv2-Gdip/b ... .ahk#L2773
by the way, there are two other places that do if (Matrix&1 = "") in other functions, which maybe we can just replace with if Matrix is not number

and if you have other changes please advise or submit a pull request

Helgef
Posts: 2990
Joined: 17 Jul 2016, 01:02
Contact:

Re: Type mismatch. AutoHotkey_2.0-a096-2ad11cb

15 May 2018, 11:27

Hello :wave: .
_3D_ wrote:

Code: [Select all] [Download] GeSHi © Codebox Plus

;...
a:= b + 123
;...

Till now it was 123 if b == "" now exception ???

No it wasn't, non-numerics in math expressions was treated as an error and yielded an empty string. Even in v1 using non-numerics in math expressions are considered an error, according to the documentation.
guest3456 wrote:wouldnt just Screen is "number" be sufficient?
Indeed, Screen & 1 != "" is superfluous, it can never be false, it can only be true or an exception :thumbup: .

Cheers.
guest3456
Posts: 2313
Joined: 09 Oct 2013, 10:31

Re: Type mismatch. AutoHotkey_2.0-a096-2ad11cb

16 May 2018, 08:42

i've updated the v2 Gdip library:
https://github.com/mmikeww/AHKv2-Gdip/c ... 0e91c64b84

this changed in v2-a95:
Changed math functions and operators to throw an exception instead of returning "" for errors.

_3D_
Posts: 176
Joined: 29 Jan 2014, 14:40

Re: Type mismatch. AutoHotkey_2.0-a096-2ad11cb

16 May 2018, 11:58

guest3456 wrote:i've updated the v2 Gdip library:
https://github.com/mmikeww/AHKv2-Gdip/c ... 0e91c64b84

this changed in v2-a95:
Changed math functions and operators to throw an exception instead of returning "" for errors.

Code: [Select all] [Download] GeSHi © Codebox Plus

if (x == "") || (y == "") || (w == "") || (h == "")
return -1
What about if x=="abc"?
Let replace with:

Code: [Select all] [Download] GeSHi © Codebox Plus

try {
_:= x + y + w + h ;check all if numbers
} catch {
return -1
}
AHKv2.0 use the future now.
guest3456
Posts: 2313
Joined: 09 Oct 2013, 10:31

Re: Type mismatch. AutoHotkey_2.0-a096-2ad11cb

16 May 2018, 15:00

_3D_ wrote:

Code: [Select all] [Download] GeSHi © Codebox Plus

if (x == "") || (y == "") || (w == "") || (h == "")
return -1
What about if x=="abc"?
Let replace with:

Code: [Select all] [Download] GeSHi © Codebox Plus

try {
_:= x + y + w + h ;check all if numbers
} catch {
return -1
}

x="abc" only if the user did something like this: Gdip_BitmapFromScreen("abc|def|ghi|xyz")
what if Screen="abc" ? Gdip_BitmapFromScreen("abc") ?

at some point the user is responsible for reading the API and using the function correctly. plus, the original Gdip used this, so we're not making changes unless necessary. this isn't meant to be a rewrite


Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 1 guest