Food for thought, a few non-junction solutions:

On 10/22/2010 06:16 AM, Damian Conway wrote:
>     # Find the list of common elements in two lists...
>     sub intersection (@list1, @list2) {
>         (any(@list1) & any(@list2).eigenstates;
>     }

sub intersection(@list1, @list2) {
    uniq gather for @list1 X @list2 -> $a, $b {
         take $a if $a eqv $b
    }
}

or

sub interseection(@list1, @list2) {
   (@list1 X=> @list2).grep({ .key eqv .value})>>.key.uniq
}

Admittedly it's not as declarative, but it's explicit about the
comparison used (which is a plus, in my eyes).

If you want to use eq or ===, hash based solutions come to mind too.

>     # Find the factors of a number...
>     sub factors (Num $n) {
>         ( $n/any(1..$n) ).eigenstates.grep({ $^q.Int == $q });
>     }


sub factors($n) {
    ($n X/ 1..$n).grep: { .Int == $_ }
}

or

sub factors($n) {
   (1..$n).grep: { %n %% $_ }
}

>     # Check for an unacceptable password, and list all when warning...
>     constant UNACCEPTABLE = any < Godel Escher Bart etc... >;
> 
>     if $passwd ~~ UNACCEPTABLE {
>         say "Unacceptable password. Don't use any of these:";
>         say UNACCEPTABLE.eigenstates¬».fmt("\t%s\n");
>     }

constant UNACCETABLE = <Godel Escher Bach>;

if $passwd ~~ any UNCACCEPTABLE {
    say "Unacceptable password. Don't use any of these:";
    say UNACCEPTABLE».fmt("\t%s\n");
}

Reply via email to