exact string compare

This forum is meant for questions and discussions about the X# language and tools
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

exact string compare

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

exact string compare

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

exact string compare

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

exact string compare

Post 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
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Chris
Posts: 4901
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

exact string compare

Post 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
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

exact string compare

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

exact string compare

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

exact string compare

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

exact string compare

Post by FFF »

Robert,
if there ist no behavioural difference of = and ==, i wonder why the "special" case == exists at all ?
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

exact string compare

Post 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 ?
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply