Skip to content
Permalink
Browse files

Fewer scalar containers for (elem)

  • Loading branch information...
lizmat committed May 9, 2019
1 parent e316c1a commit 7db3a06dd7bfee18f958cf3dd48b7706414d4f2f
Showing with 26 additions and 26 deletions.
  1. +26 βˆ’26 src/core/set_elem.pm6
@@ -7,16 +7,16 @@
# ∌ does NOT contain

proto sub infix:<(elem)>($, $, *% --> Bool:D) is pure {*}
multi sub infix:<(elem)>(Str:D $a, Map:D $b --> Bool:D) {
multi sub infix:<(elem)>(Str:D \a, Map:D \b --> Bool:D) {
nqp::hllbool(
nqp::istrue(
nqp::elems(my \storage := nqp::getattr(nqp::decont($b),Map,'$!storage'))
nqp::elems(my \storage := nqp::getattr(nqp::decont(b),Map,'$!storage'))
&& nqp::if(
nqp::eqaddr($b.keyof,Str(Any)),
nqp::atkey(storage,$a), # normal hash
nqp::eqaddr(b.keyof,Str(Any)),
nqp::atkey(storage,a), # normal hash
nqp::getattr( # object hash
nqp::ifnull(
nqp::atkey(storage,$a.WHICH),
nqp::atkey(storage,a.WHICH),
BEGIN # provide virtual value False # did not exist
nqp::p6bindattrinvres(nqp::create(Pair),Pair,'$!value',False)
),
@@ -27,15 +27,15 @@ multi sub infix:<(elem)>(Str:D $a, Map:D $b --> Bool:D) {
)
)
}
multi sub infix:<(elem)>(Any $a, Map:D $b --> Bool:D) {
multi sub infix:<(elem)>(Any \a, Map:D \b --> Bool:D) {
nqp::hllbool(
nqp::istrue(
nqp::elems( # haz a haystack
my \storage := nqp::getattr(nqp::decont($b),Map,'$!storage')
) && nqp::not_i(nqp::eqaddr($b.keyof,Str(Any))) # is object hash
my \storage := nqp::getattr(nqp::decont(b),Map,'$!storage')
) && nqp::not_i(nqp::eqaddr(b.keyof,Str(Any))) # is object hash
&& nqp::getattr(
nqp::ifnull(
nqp::atkey(storage,$a.WHICH), # exists
nqp::atkey(storage,a.WHICH), # exists
BEGIN # provide virtual value False # did not exist
nqp::p6bindattrinvres(nqp::create(Pair),Pair,'$!value',False)
),
@@ -45,21 +45,21 @@ multi sub infix:<(elem)>(Any $a, Map:D $b --> Bool:D) {
)
)
}
multi sub infix:<(elem)>(Int:D $a, Range:D $b --> Bool:D) {
$b.is-int ?? $b.ACCEPTS($a) !! infix:<(elem)>($a,$b.iterator)
multi sub infix:<(elem)>(Int:D \a, Range:D \b --> Bool:D) {
b.is-int ?? b.ACCEPTS(a) !! a (elem) b.iterator
}
multi sub infix:<(elem)>(Any $a, Iterable:D $b --> Bool:D) {
infix:<(elem)>($a,$b.iterator)
multi sub infix:<(elem)>(Any \a, Iterable:D \b --> Bool:D) {
a (elem) b.iterator
}
multi sub infix:<(elem)>(Any $a, Iterator:D $b --> Bool:D) {
multi sub infix:<(elem)>(Any \a, Iterator:D \b --> Bool:D) {
nqp::if(
$b.is-lazy,
b.is-lazy,
Failure.new(X::Cannot::Lazy.new(:action<(elem)>)),
nqp::stmts(
(my str $needle = $a.WHICH),
(my str $needle = a.WHICH),
nqp::until(
nqp::eqaddr(
(my \pulled := nqp::decont($b.pull-one)),
(my \pulled := nqp::decont(b.pull-one)),
IterationEnd
),
nqp::if(
@@ -71,32 +71,32 @@ multi sub infix:<(elem)>(Any $a, Iterator:D $b --> Bool:D) {
)
)
}
multi sub infix:<(elem)>(Any $a, QuantHash:D $b --> Bool:D) {
multi sub infix:<(elem)>(Any \a, QuantHash:D \b --> Bool:D) {
nqp::hllbool(
(my \elems := $b.RAW-HASH) ?? nqp::existskey(elems,$a.WHICH) !! 0
(my \elems := b.RAW-HASH) ?? nqp::existskey(elems,a.WHICH) !! 0
)
}

multi sub infix:<(elem)>(Any $, Failure:D $b) { $b.throw }
multi sub infix:<(elem)>(Failure:D $a, Any $) { $a.throw }
multi sub infix:<(elem)>(Any $a, Any $b) { infix:<(elem)>($a,$b.Set) }
multi sub infix:<(elem)>(Any $, Failure:D \b) { b.throw }
multi sub infix:<(elem)>(Failure:D \a, Any $) { a.throw }
multi sub infix:<(elem)>(Any \a, Any \b) { a (elem) b.Set }

# U+2208 ELEMENT OF
my constant &infix:<∈> := &infix:<(elem)>;

# U+2209 NOT AN ELEMENT OF
proto sub infix:<βˆ‰>($, $, *%) is pure {*}
multi sub infix:<βˆ‰>($a, $b --> Bool:D) { not $a (elem) $b }
multi sub infix:<βˆ‰>(\a, \b --> Bool:D) { not a (elem) b }

proto sub infix:<(cont)>($, $, *%) is pure {*}
multi sub infix:<(cont)>($a, $b --> Bool:D) { $b (elem) $a }
multi sub infix:<(cont)>(\a, \b --> Bool:D) { b (elem) a }

# U+220B CONTAINS AS MEMBER
proto sub infix:<βˆ‹>($, $, *%) is pure {*}
multi sub infix:<βˆ‹>($a, $b --> Bool:D) { $b (elem) $a }
multi sub infix:<βˆ‹>(\a, \b --> Bool:D) { b (elem) a }

# U+220C DOES NOT CONTAIN AS MEMBER
proto sub infix:<∌>($, $, *%) is pure {*}
multi sub infix:<∌>($a, $b --> Bool:D) { not $b (elem) $a }
multi sub infix:<∌>(\a, \b --> Bool:D) { not b (elem) a }

# vim: ft=perl6 expandtab sw=4

0 comments on commit 7db3a06

Please sign in to comment.
You can’t perform that action at this time.