in reply to Unobvious Pathological Code Snippets

This, (attributable to Juerd) is kinda cute, and a little surprising:

my @a = '01' .. '30'; print "@$_" for sub{ my $n=shift; map{ [ splice @_, 0, $n ] } 0 .. @_ / $n }->( 5, @a ); 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 print @a; 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2 +4 25 26 27 28 29 30

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Unobvious Pathological Code Snippets
by QM (Parson) on Mar 28, 2006 at 18:52 UTC
    <Tim "The Toolman" Taylor>

    Hrruuhhhh???

    </Tim "The Toolman" Taylor>

    While that's devilish and all that, how is it pathological? Heck, it doesn't even DWIM unless $n divides @_.

    The interesting bit, to me, is passing arguments to the anonymous sub.

    I guess I should have stated more explicitly that I'm looking for things that can't be grokked without deep diving into the docs or the source code. For instance, the continue/next behavior is documented, rather humorously, as "entertaining", without being so explicit as to spoil the fun.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

      The thing to note is that despite having "destructively" spliced the array into chunks, the array remains unchanged after the process.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Oh, OK. I wasn't expecting this, but it's within the parameters, Jim ;)

        Is it then a copy instead of the original?

        So what are the critical characteristics? Is it the anonymous sub? The map? Or the whole gestalt? (And is "whole gestalt" pleonastic?)

        -QM
        --
        Quantum Mechanics: The dreams stuff is made of