Smylers wrote:
> > Thanks to context-forcing, the string/numeric distinction is still
> > there, at the expense of a little extra verbosity:
> > 
> >     +$a == +$b;  # Numeric compare
> >     ~$a == ~$b;  # String compare
> >      $a ==  $b;  # Generic compare
> 
> But what does a 'generic' compare do?  While Perl 6 has typed variables,
> I get the impression that these are most useful for efficiency reasons
> (especially for array and hash elements), and that it'll still be common
> -- especially in simple scripts -- to continue to use Perl-5-style
> scalar variables.
> 
> This very often leads to variables that contain textual representation
> of numbers.  Pretty much all input from files, the keyboard, databases,
> and from a web forms comes in as text even if its source considers it to
> be numeric.  Likewise, in the programmer's mind such data is numeric.
> Doing a string comparison because it currently happens to be stored as a
> string is far too confusing.
> 
> The other reason for not having unary C<+> and C<~> to force numeric or
> string context is the reason that Larry gave when we were discussing the
> bitwise operators.  Somebody suggested that a single operator could do
> for both numeric and character operations, using these symbols on the
> operands to resolve ambiguities.
> 
> Larry rejected the idea, on the grounds that operands can be arbitrarily
> complex expressions, and that can leave the C<+> or C<~> for the left
> operand a considerable distance from the operator on which it has an
> effect.

Very well put.  My solution sucks.

However, my problem remains.  What does the poor generic programmer do
when he needs generic equality!?  Particularly, what does 
Hash(keyed => Object) use?

Maybe a method in object, or a multimethod?  Called C<same> or
somesuch?  Something just rings false about that :).

To outline the problem again, even disregarding user-defined objects:
Generic containers need a way to compare nums to nums and strings to
strings and only get true when they actually are equal.  The kind that
the user overloads with his own user-defined type to say what it means
to be equal.  No magic.

Ooh!  And I came up with a good identity operator!  :== (or =:= if you
like symmetry).  There's a beautiful parallel with := .

    $a = $b;
    $a == $b;   # is always true

    $a := $b;
    $a :== $b;  # is always true
   ($a =:= $b;  # looks a little better)

Luke

Reply via email to