==-operator, the final word

Found a bug in the language, the VM or the compiler? help us iron things out or give ideas for doing things better.
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
User avatar
Dragonlord
Forum Administrator
Posts:609
Joined:Fri Jul 30, 2004 4:30 pm
Location:Switzerland
Contact:
==-operator, the final word

Post by Dragonlord » Thu Sep 30, 2004 3:28 pm

After a couple of this-way and that-way I'll now fixate the way the ==-operator is handeled. The attempt of allowing '==' to be overloaded doesn't really work fluid in a static-typed environment like DS is and thus a cheaper, and less flexible way has to be found.

so I went back to the old way of handling the == operator on Objects and this one works. The following changes are now in the SVN.

- comparing two Objects using '==' or '!=' is now a primitive operation (like int==int) and thus can compared null-objects on both sides without problems.
- Objects has the 'equals' function which can and has to be overloaded in a derived class to implement content-compare. Beware one thing. The compiler will not choke on you if you implement an equals-function taking your object class as paramater as this is considered a different function so always use 'Object' as the function parameter.
Image
Oh to be a dragon, of silkworm size or immense...

User avatar
Khan
Intermediate
Posts:69
Joined:Fri Sep 17, 2004 9:31 am
Location:src/packages/collections/
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Never say never

Post by Khan » Sat Oct 02, 2004 11:24 am

First I have to say I can live with the current situation introduced with revision 24.
But what was this Bond movie called again?

This a Micro$~1 solution so it's bad and a h4x but I post it anyway as a discussion base. In C# all operators are class members (and can therefore not be put in an iterface).
So in DS this would probably look like this.

Code: Select all

public static operator bool == (Object arg1, Object arg2)
     if isnull arg1 and isnull arg2
          return true
     else if isnull arg1 xor insull arg2
          return false
     else
          ... # preform real comparison here
     end
end
BTW did you actually notice we have more posts here than in the other forums gother?

User avatar
Dragonlord
Forum Administrator
Posts:609
Joined:Fri Jul 30, 2004 4:30 pm
Location:Switzerland
Contact:

Post by Dragonlord » Sat Oct 02, 2004 6:15 pm

grin... yeah... is somehow funny...

about that operator thingy. the c++ way is effectivly a rather nasty hack there. it works but in fact you end up with what you want to evade using OOP, that you use static functions all over the place. and '==' can not be overloaded, like '+' can not be overloaded and this is a bit of a downside.

makes me think about something... i'm not sure if you can defined operators in interfaces in DS. we've got to try this ;)
Image
Oh to be a dragon, of silkworm size or immense...

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable