xsharp.eu • exact string compare
Page 1 of 3

exact string compare

Posted: Tue Oct 11, 2016 12:12 pm
by wriedmann
Hello,

sometimes in VO I'm writing such code:

if ! cString1 == cString2

because

if cString1 != cString2

depends on SetExact(). Personally I would like an operator like "!==" to have an exact version of "!=" like "==" for "="

If there is already something similar, please ignore. And of course, it has absolutely no priority.

Wolfgang

exact string compare

Posted: Tue Oct 11, 2016 3:23 pm
by robert
Wolfgang,

In the core dialect afaik there is no difference between string = string and string == string.

Similarly string != string is the same as !(string == string).

We could add an operator !== and map it to the Core != operator for all dialects if you want.
That should not be too difficult.

Robert

exact string compare

Posted: Tue Oct 11, 2016 3:39 pm
by wriedmann
We could add an operator !== and map it to the Core != operator for all dialects if you want.
That should not be too difficult.
That would be very welcome! I will have a LOT of code in Vulcan and VO dialects in the future. New code is always written in Core dialect. And so I don't have to think about the dialect when working in older code.

Wolfgang

exact string compare

Posted: Tue Oct 11, 2016 5:16 pm
by FFF
Robert wrote:Wolfgang,

In the core dialect afaik there is no difference between string = string and string == string

Robert
pmfji, that means, in core you can't (easily) compare substring with fullstring?
Just had a go:
FUNCTION Start() AS VOID
LOCAL c1, c2 AS STRING
? "c1 = ", c1:= "a"
? "c2 = ", c2:="abc"

?"c1==c2: " ,c1==c2
? "c2==c1: ", c2==c1
?"c1=c2: " ,c1=c2
? "c2=c1: ", c2=c1
Return

the last two lines won't compile in core - "no such operator".

?
Karl

exact string compare

Posted: Tue Oct 11, 2016 6:50 pm
by Chris
Hi Karl,

The partial string compare operator is not a compiler thing, it is implemented through a runtime function because its behavior depends on different things like the state of SetExact(), the type of the operands etc. The Core dialect has no runtime, so this operator is not supported.

Theoretically we could implement it at the compiler level in Core, but that would cause trouble like it would have different results than in the other dialects and also what would the "!=" operator mean then? Should it be the opposite of "=" or the opposite of "=="?. In VO the behavior of that operator is crazy, depending on the operands it some cases it means !(==) and in others !(=). It was obviously a big nightmare emulating the same behavior in vulcan for compatibility with VO.. The Core dialect is the "cleanest" x# dialect, so I think it's better leaving this feature out in this dialect.

Chris

exact string compare

Posted: Tue Oct 11, 2016 7:45 pm
by wriedmann
Hi Chris,
In VO the behavior of that operator is crazy, depending on the operands it some cases it means !(==) and in others !(=).
I couldn't agree more!

Therefore in VO I'm always writing

if ! cString1 == cString2

and I'm very happy that at least in the Core dialect this problem is solved.

Wolfgang

exact string compare

Posted: Tue Oct 11, 2016 8:11 pm
by robert
Karl,

You are right. The single equals operator does not work in the Core dialect for strings. We only support the double equals.

To compare a substring you need to use the String.Compare() method and pass it the start position and length that you want to compare.

Robert

exact string compare

Posted: Tue Oct 11, 2016 8:15 pm
by robert
Wolfgang,

I have added the !== operator earlier today. It does what you asked for.
And I discovered that the != operator for Strings was not doing the same that the Vulcan operator did, but now it does: it calls a runtime function for its wok.
And the <> operator and the # operator do the same as the != operator.

Robert

exact string compare

Posted: Tue Oct 11, 2016 8:31 pm
by FFF
Robert,
if there ist no behavioural difference of = and ==, i wonder why the "special" case == exists at all ?

exact string compare

Posted: Tue Oct 11, 2016 8:36 pm
by robert
Karl,

Compatibility, compatibility.
We have to support the difference between '=' and '==' for the VO and Vulcan dialect.
And like i said before: the '=' operator is NOT supported for strings in the Core language because it depends on a runtime function (which again depends on the SetExact setting)

Robert
FFF wrote:Robert,
if there ist no behavioural difference of = and ==, i wonder why the "special" case == exists at all ?