The table of smart matches in S4 has this:

    Any     Str       string equality          match if $_ eq $x
    Any     Rule      pattern match            match if $_ ~~ /$x/

By my (and Damian's) interpretation of the table, this means
that "string" ~~ /rule/ would be interpreted as testing the
*string equality* of its operands, rather than doing a pattern

Clearly this is not the intention. Am I misreading the table,
or is there a mistake? If the latter, what is the correct
precedence order of the table entries?

The other thing that seems odd to me is that

  $foo ~~ $bar

where $foo and $bar are both references to Code<>, is defined
to be equal to (the truth value of) $bar(). This seems an
unnecessary violation of commutativity.

For Perl 5, I changed the relevant part of the table to

    Any     undef     undefined                match if !defined $a
    Any     Regex     pattern match            match if $a =~ /$b/
    Code()  Code()    results are equal        match if $a->() eq $b->()
    Any     Code()    simple closure truth     match if $b->() (ignoring $a)
    Num     numish[!] numeric equality         match if $a == $b
    Any     Str       string equality          match if $a eq $b
    Any     Num       numeric equality         match if $a == $b

which retains commutativity in all cases. Of course it's
different in Perl 6, because the "dotted entries" like
.[number] and .method need to behave non-commutatively.
But is it really necessary for coderefs?

Is my implementation sufficiently in the spirit of the Perl 6

Thanks for your thoughts.


Reply via email to