set_multiply.pm6 (rakudo-2020.09) | : | set_multiply.pm6 (rakudo-2020.10) | ||
---|---|---|---|---|
# This file implements the following set operators: | # This file implements the following set operators: | |||
# (.) set multiplication (ASCII) | # (.) set multiplication (ASCII) | |||
# ⊍ set multiplication | # ⊍ set multiplication | |||
proto sub infix:<(.)>(|) is pure {*} | proto sub infix:<(.)>(|) is pure {*} | |||
multi sub infix:<(.)>() { bag() } | multi sub infix:<(.)>() { bag() } | |||
multi sub infix:<(.)>(Setty:D \a) { a.Baggy } | multi sub infix:<(.)>(Setty:D \a) { a.Baggy } | |||
multi sub infix:<(.)>(Baggy:D \a) { a } # also Mixy | multi sub infix:<(.)>(Baggy:D \a) { a } # also Mixy | |||
multi sub infix:<(.)>(Any \a) { a.Bag } | ||||
multi sub infix:<(.)>(Setty:D \a, Setty:D \b) { | multi sub infix:<(.)>(Setty:D \a, Setty:D \b) { | |||
nqp::if( | nqp::if( | |||
(my $elems := a.Bag.RAW-HASH) && nqp::elems($elems), | (my $elems := a.Bag.RAW-HASH) && nqp::elems($elems), | |||
nqp::create(a.WHAT.Baggy).SET-SELF( | nqp::create(a.WHAT.Baggy).SET-SELF( | |||
Rakudo::QuantHash.MULTIPLY-SET-TO-BAG($elems,b.RAW-HASH), | Rakudo::QuantHash.MULTIPLY-SET-TO-BAG($elems,b.RAW-HASH), | |||
), | ), | |||
a.Baggy | a.Baggy | |||
) | ) | |||
} | } | |||
skipping to change at line 66 | skipping to change at line 65 | |||
infix:<(.)>( | infix:<(.)>( | |||
nqp::isconcrete(a) | nqp::isconcrete(a) | |||
?? nqp::istype(a,Setty) | ?? nqp::istype(a,Setty) | |||
?? a.Baggy | ?? a.Baggy | |||
!! nqp::istype(a,Baggy) ?? a !! a.Bag | !! nqp::istype(a,Baggy) ?? a !! a.Bag | |||
!! a.Bag, | !! a.Bag, | |||
b.Bag | b.Bag | |||
) | ) | |||
} | } | |||
multi sub infix:<(.)>(**@p) { | multi sub infix:<(.)>(+@p) { # also Any | |||
my $result = @p.shift; | my $result := @p.shift; | |||
$result = $result (.) @p.shift while @p; | if @p { | |||
$result | $result := $result (.) @p.shift while @p; | |||
$result | ||||
} | ||||
else { | ||||
$result.Bag | ||||
} | ||||
} | } | |||
# U+228D MULTISET MULTIPLICATION | # U+228D MULTISET MULTIPLICATION | |||
my constant &infix:<⊍> := &infix:<(.)>; | my constant &infix:<⊍> := &infix:<(.)>; | |||
# vim: expandtab shiftwidth=4 | # vim: expandtab shiftwidth=4 | |||
End of changes. 2 change blocks. | ||||
5 lines changed or deleted | 9 lines changed or added |