Luke Palmer wrote:
> However, my problem remains.  What does the poor generic programmer do
> when he needs generic equality!?

Well, I'm a pretty generic programmer.  I spend lots of time glued to the
monitor, I have poor social skills, sometimes my boss has to tell me to
dress neater...

Anyway, maybe I'm just repeating what was already said in bigger words,
but let me propose a concept:

=:= is a "generic" comparison operator that simply calls the
value_for_comparison method of the objects on left and right.  If they
both return the same string, then the expression returns true, else it
returns false. If they don't have that method, that's a fatal error.
Their value_for_comparison() methods must have been defined in the same
class, otherwise you're comparing apples and oranges.  (Yes, I'm sure we
can think of a better name than "value_for_comparison".)

Of course, you can also cast the objects to change what type of comparison
you want.  So, for example, C<$a =:= $b> compares the outputs of the
value_for_comparison methods, but C<~$a =:= ~$b> compares the numification
of the objects, or, to get into the guts of the matter, the objects are
evaluated in numeric context, which causes them to run their overflow
methods for numification, which returns number objects, which then call
their value_for_comparison methods, which return the numbers as
represented by some string which is formatted according to some
unambiguous rule (we already have those unabiguou rules).

==, then, becomes just an alias for C<~$a =:= ~$b> and eq becomes an alias
for C<+$a =:= +$b>.  To find out if the two variables reference the same
object, you simply cast them as the fundamental class from which all
objects extend.  Um, I don't remember the cast operator to do that (is
there one?) but say it's simply "ob", you just say C<ob $a =:= $ob $b>.

-Miko


Miko O'Sullivan
Programmer Analyst
Rescue Mission of Roanoke






Reply via email to