Question Stefan Cronje · Feb 23, 2023

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")
1

In Python:

>>> print("45" < "46")
True
>>> print("45" > "46")
False
>>> print("V45" < "V46")
True
>>> print("V45" > "V46")
False
>>> print("V45" <= "V46")
True
>>> print("V45" >= "V46")
False
Product version: Ensemble 2018.1

Comments

Vitaliy Serdtsev · Feb 23, 2023

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" -> 0
0
Stefan Cronje · Feb 23, 2023

That is helpful, thank you.

I just find it strange that it is quite non-standard compared to other compilers/interpreters

0
Robert Cemper  Feb 24, 2023 to Stefan Cronje

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!

0