Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Flesh out eqv a bit more.
  • Loading branch information
jnthn committed Jul 9, 2011
1 parent 20abe0d commit bab5ed2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/core/Any.pm
Expand Up @@ -106,15 +106,40 @@ proto infix:<after>(|$) { * }
multi infix:<after>($x?) { Bool::True }
multi infix:<after>(\$a, \$b) { ($a cmp $b) > 0 }

proto infix:<===>($a?, $b?) { * }
multi infix:<===>($a?) { Bool::True }
multi infix:<===>($a, $b) { $a.WHICH === $b.WHICH }
proto infix:<===>(Mu $a?, Mu $b?) { * }
multi infix:<===>(Mu $a?) { Bool::True }
multi infix:<===>(Mu $a, Mu $b) { $a.WHICH === $b.WHICH }

proto sub infix:<eqv>($, $) { * }
multi sub infix:<eqv>($a, $b) {
$a.WHAT === $b.WHAT && ($a cmp $b) == 0;
proto sub infix:<eqv>(Mu $, Mu $) { * }
multi sub infix:<eqv>(Mu $a, Mu $b) {
$a.WHAT === $b.WHAT && $a === $b
}
multi sub infix:<eqv>(@a, @b) {
unless @a.WHAT === @b.WHAT && @a.elems == @b.elems {
return Bool::False
}
for ^@a -> $i {
unless @a[$i] eqv @b[$i] {
return Bool::False;
}
}
Bool::True
}
multi sub infix:<eqv>(EnumMap $a, EnumMap $b) {
if +$a != +$b { return Bool::False }
for $a.kv -> $k, $v {
unless $b.exists($k) && $b{$k} eqv $v {
return Bool::False;
}
}
Bool::True;
}
multi sub infix:<eqv>(Numeric $a, Numeric $b) {
$a.WHAT === $b.WHAT && ($a cmp $b) == 0
}
multi sub infix:<eqv>(Stringy $a, Stringy $b) {
$a.WHAT === $b.WHAT && ($a cmp $b) == 0
}


# XXX: should really be '$a is rw' (no \) in the next four operators
proto prefix:<++>(|$) { * }
Expand Down
1 change: 1 addition & 0 deletions src/core/stubs.pm
Expand Up @@ -5,6 +5,7 @@
# in the end.
my class Whatever is Cool { ... }
my class WhateverCode is Code { ... }
my role Stringy { ... }
my class Bag is Iterable does Associative { }
my class Buf is Iterable does Positional { }
my class Set is Iterable does Associative { }
Expand Down

0 comments on commit bab5ed2

Please sign in to comment.