Adam Kennedy kirjoitti:
[»+^=«] reminds me of a P5 regex that has a comment saying "This is
black magic. Don't touch!". --That's-- my complaint.

I look at...

 >>but the basic operator there is just ^, with a + modifier to indicate
 >>numeric XOR, = to indicate an assignment operator, »« to indicate
 >>explicit parallelism, and now [] to indicate reduction

...and I just mind-wipe... so it's doing WHAT exactly? I've read it 5 times and I still have no idea. And reduction? I write 25,000+ lines of Perl a year, and if you are talking about something like List::Util::reduce, I think I've used it maybe twice?

Just trying to guess: (Here @a, @b, @c all have same length for simplicity)

    [>>+^=<<] (@a, @b, @c)

    # reduction: place the op between each item in the given list

    @a >>+^=<< @b >>+^=<< @c

    # hyper-op: apply op in parallel for items in lists

    for @a Y @b Y @c -> $a is rw, $b is rw, $c {
        $a +^= $b +^= $c
    }

    # and finally (+^= is right-associative)

    for @a Y @b Y @c -> $a is rw, $b is rw, $c {
        $b = $b +^ $c;
        $a = $a +^ $b;
    }


I'm not too familiar with xor, so here's an easier example with plain +=

    my @a = (1,2,3);
    my @b = (10,20,30);
    my @c = (100,200,300);

    [>>+=<<] (@a, @b, @c);

    # i.e. @a >>+=<< @b >>+=<< @c

    # now @c = (100, 200, 300)
    #     @b = (110, 220, 330)
    #     @a = (111, 222, 333)


-- Markus Laire <Jam. 1:5-6>

Reply via email to