Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: reduce like iterators

by LanX (Saint)
on Jan 15, 2024 at 17:56 UTC ( [id://11157005]=note: print w/replies, xml ) Need Help??


in reply to reduce like iterators

Hello younger me :)

> and List::MoreUtils doesn't seem to provide anything better

This changed in the meantime, slide was added, but there are still issues.

The worst one is that it only returns scalars instead of lists like map does, which means we have to add an extra grep to filter undefined values :/

use v5.12; use warnings; use List::MoreUtils qw/slide/; use Data::Dump; my @x= split',', q(a,a,a,a,b,c,c,a,a,d,e,e,e,e); dd grep defined, slide { $a ne $b ? $b : () } "", @x;

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: reduce like iterators (BUG in List::MoreUtils::slide)
by LanX (Saint) on Jan 29, 2024 at 22:38 UTC
    > The worst one is that it only returns scalars instead of lists like map does, which means we have to add an extra grep to filter undefined values :/

    That's most likely a bug in the XS implementation of slide.

    I looked into the Pure Perl implementation in List::MoreUtils::PP, and it looked fine, it's literally using map

    And a test reveals, that it really works like it should.

    use v5.12; use warnings; use Data::Dumper; BEGIN { $ENV{LIST_MOREUTILS_PP} = 1 }; # enforce PP version, comment f +or XS use List::MoreUtils qw/slide/; my @x= split',', q(a,a,a,a,b,c,c,a,a,d,e,e,e,e); print Dumper slide { $a ne $b ? $b : () } "", @x;

      PP version

      $VAR1 = 'a'; $VAR2 = 'b'; $VAR3 = 'c'; $VAR4 = 'a'; $VAR5 = 'd'; $VAR6 = 'e';

      XS version

      $VAR1 = 'a'; $VAR2 = undef; $VAR3 = undef; $VAR4 = undef; $VAR5 = 'b'; $VAR6 = 'c'; $VAR7 = undef; $VAR8 = 'a'; $VAR9 = undef; $VAR10 = 'd'; $VAR11 = 'e'; $VAR12 = undef; $VAR13 = undef; $VAR14 = undef;

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      > That's most likely a bug in the XS implementation of slide.

      The word "bug" should be a link to the actual bug report.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        I already reported it in private, it's complicated....

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11157005]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2026-04-17 05:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.