‘18’>7 will not throw? Topic is solved

Discuss the future of the AutoHotkey language
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

‘18’>7 will not throw?

31 Jul 2023, 01:00

Since some functions like isdigit only support String without convesion, Shouldn't ‘18’>7 be replaced by Number('18')>7? Currently it will not throw but lead to an implicit conversion.
If operator overloading has been implemented, these below would certainly be more consistent:

Code: Select all

OutputDebug(18>7)  ; it will output 1
OutputDebug('18'>'7')  ; it would output 0, just like strComepare, perhaps case insensitive, has overloaded to >. But currently it will output 1
OutputDebug('18'>7)  ;it would throw, as an implicit conversion is probably unintended for a user.
Last edited by V2User on 31 Jul 2023, 06:18, edited 1 time in total.
lexikos
Posts: 9635
Joined: 30 Sep 2013, 04:07
Contact:

Re: ‘18’>7 will not throw?  Topic is solved

31 Jul 2023, 03:39

Since some functions don't perform implicit conversion, nothing anywhere in the language or library should perform implicit conversion? No. :roll:

The reasoning for IsDigit and co. is explained in the Remarks section of the documentation. The same reasoning does not apply to >.

"Operator reloading" isn't a real thing. I assume you mean "operator overloading".

I'm not considering any changes to these operators, even if it could be done in a backward-compatible way. They were specifically changed in v2.0 to always perform numeric comparison. There's nothing more consistent than always.

A user may be comparing a number read from an IniFile or window title (for example) with a number written in the script. The user almost certainly intends a numeric comparison - because that's the only thing the operator does - and an implicit conversion achieves that.

Furthermore, the documentation indicates that implicit conversions generally are performed, so the user should expect it.
A string of digits (or any other supported number format) is automatically interpreted as a number when a math operation or comparison requires it.

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 8 guests