NumOp/StrOp (with respect to !=/!==)
Posted: 13 Aug 2018, 14:09
- I've noticed a lot of suggestions here re. changing string/number handling.
Pull Requests · Lexikos/AutoHotkey_L · GitHub
https://github.com/Lexikos/AutoHotkey_L/pulls
- I welcome the != change, as now (var1 != var2) and !(var = var2) are consistent. However, one side effect is that !(var1 != var2), dependent on A_StringCaseSense, is no longer available, with no good alternative at present.
- I thought that the following might be useful:
- And potentially something like this:
- Btw should Integer("abc") return 0? And Float("abc") return 0.0?
- The way I see it, we mainly need an IsNum (looks numeric) function, prior to (or instead of) using Integer and Float. And scripts should not normally be expecting possible errors, which then need to be handled.
- Also I'm a little concerned that something as fundamental as string/number handling in expressions is being dealt with in a slightly cavalier/backdoor way via GitHub 'Pull Requests', instead of receiving the full attention and scrutiny of the AutoHotkey v2 Development forum.
- I think that the AHK v1 behaviour was fine, it was very practical and convenient, a strength of AutoHotkey. If people object to the use of "" var or var+0, perhaps functions should be available to guarantee the desired behaviour, and present it in a tidy way. Hence my suggestions above.
- While some people's suggestions are potentially increasing consistencies in some areas, they are also creating new problems, such as potentially preventing string comparisons via operators, and the sum of those changes could be quite a lot worse than what we had in AHK v1.
- Anyhow, I'd rather see people lay out a complete and consistent vision of the way forward, rather than a drip feed of source code suggestions.
Pull Requests · Lexikos/AutoHotkey_L · GitHub
https://github.com/Lexikos/AutoHotkey_L/pulls
- I welcome the != change, as now (var1 != var2) and !(var = var2) are consistent. However, one side effect is that !(var1 != var2), dependent on A_StringCaseSense, is no longer available, with no good alternative at present.
- I thought that the following might be useful:
Code: Select all
NumOp(op, var) ;unary (2 params)
NumOp(var1, op, var2) ;binary (3 params)
NumOp(var1, op1, var2, op2, var3) ;ternary (5 params)
StrOp(op, var) ;unary (2 params)
StrOp(var1, op, var2) ;binary (3 params)
StrOp(var1, op1, var2, op2, var3) ;ternary (5 params)
;e.g.
NumOp(var1, ">=", var2, "<=", var3) ;ternary (numeric between)
StrOp(var1, ">=", var2, "<=", var3) ;ternary (string between)
Code: Select all
result := (var1 Op(vOpName) var2)
- The way I see it, we mainly need an IsNum (looks numeric) function, prior to (or instead of) using Integer and Float. And scripts should not normally be expecting possible errors, which then need to be handled.
- Also I'm a little concerned that something as fundamental as string/number handling in expressions is being dealt with in a slightly cavalier/backdoor way via GitHub 'Pull Requests', instead of receiving the full attention and scrutiny of the AutoHotkey v2 Development forum.
- I think that the AHK v1 behaviour was fine, it was very practical and convenient, a strength of AutoHotkey. If people object to the use of "" var or var+0, perhaps functions should be available to guarantee the desired behaviour, and present it in a tidy way. Hence my suggestions above.
- While some people's suggestions are potentially increasing consistencies in some areas, they are also creating new problems, such as potentially preventing string comparisons via operators, and the sum of those changes could be quite a lot worse than what we had in AHK v1.
- Anyhow, I'd rather see people lay out a complete and consistent vision of the way forward, rather than a drip feed of source code suggestions.