Created
July 10, 2015 11:56
-
-
Save anonymous/571b2a3c97a6176a6ecf to your computer and use it in GitHub Desktop.
weird behavior with eqv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
class Node does Positional | |
{ | |
has ( $.Str, @.list ); | |
submethod BUILD( :$node ) { @!list = ( $!Str = $node ).comb: / \D+ | \d+ / } | |
method AT-POS( *@i ) { @!list[@i] } | |
method cmp( Node $n ) | |
{ | |
my $i = self.ind( $n ); | |
$i.defined ?? @!list[$i] cmp $n[$i] !! $!Str leg $n; | |
} | |
method ind( Node $n ) | |
{ | |
my @i = $n.keys.grep: { @!list[$_] ne $n[$_] } if @!list == +$n; | |
## why does the line below not work with !eqv ? | |
## my @i = $n.keys.grep: { @!list[$_] !eqv $n[$_] } if @!list == +$n; | |
## say @i; ## with input below this should be 1, not 0, 1 | |
return @i == 1 ?? @i[0] !! Nil; | |
} | |
} | |
multi prefix:<+>( Node $n ) { $n.elems } | |
multi infix:<~>( Node $l, Node $r ) { Node.new: :node{ $l ~ $r } } | |
multi infix:<*>( Node $l, Node $r ) { $l.ind: $r } | |
multi infix:<cmp>( Node $l, Node $r ) { $l.cmp: $r } | |
my $a = Node.new( :node<abc000> ); | |
my $b = Node.new( :node<abc001> ); | |
say $a * $b; ## expecting 1, which is the index $a and $b have in common |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment