Issue with Logical Operators on Strings
Hi all,
I might be losing my mind or do not understand how ObjectScript does string comparisons, but the following does not look right to me.
Is it really possible that you can't compare non-numerical strings other than with an equals or not equals?
USER>w ("45" < "46")
1
USER>w ("45" > "46")
0
USER>w ("V45" < "V46")
0
USER>w ("V45" > "V46")
0
USER>w ("V45" <= "V46")
1
USER>w ("V45" >= "V46")
1In Python:
>>> print("45" < "46")
True
>>> print("45" > "46")
False
>>> print("V45" < "V46")
True
>>> print("V45" > "V46")
False
>>> print("V45" <= "V46")
True
>>> print("V45" >= "V46")
FalseComments
You need to use the Sorts After operator ]] to do this.
See https://docs.intersystems.com/iris20223/csp/docbook/Doc.View.cls?KEY=GC…
See String-to-Number Conversion and further.
w ("45" < "46") === 45 < 46
w ("45" > "46") === 45 > 46
w ("V45" < "V46") === 0 < 0
w ("V45" > "V46") === 0 > 0
w ("V45" <= "V46") === 0 <= 0
w ("V45" >= "V46") === 0 >= 0
w +"45" -> 45
w +"V45" -> 0That is helpful, thank you.
I just find it strange that it is quite non-standard compared to other compilers/interpreters
You have to blame the designers of the language back in the 60ties of last century.
it was even an ANSI Standart then.
And it is backward compatible and the code of the 60ties still can run unchanged!