Skip Menu |
 

This queue is for tickets about the List-MoreUtils CPAN distribution.

Report information
The Basics
Id: 132043
Status: resolved
Priority: 0/
Queue: List-MoreUtils

People
Owner: Nobody in particular
Requestors: henrik.pauli [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.428
Fixed in: (no value)



Subject: listcmp behaviour mismatch (between XS and PP, and to the doc)
Download (untitled) / with headers
text/plain 1.2k
I noticed that contrary to what the manual seems to say, in scalar context, listcmp does not return what we would think it does. Here's the doc: my $cmp = listcmp @seq, @prim, @fib; # returns { 1 => [0, 2], 2 => [0, 1, 2], 3 => [0, 1], 5 => [1] } i.e. it supposedly returns a hashref (in place of the plain hash in list context). Attached is a short script to test this behaviour. Here is its output: List::MoreUtils::XS version is: 0.428 List::MoreUtils::PP version is: 0.428 [XS] $\%cmp = { '1' => [ 0, 1 ], '3' => [ 0, 1 ], '2' => [ 0, 1 ] }; $cmp = [ 0, 1 ]; [PP] $\%cmp = { '3' => [ 0, 1 ], '1' => [ 0, 1 ], '2' => [ 0, 1 ] }; $cmp = 3; In both cases the hashes are correct, and the scalar context values are not, in neither case is it a hashref, and they also differ from each other.
Subject: moreutils-listcmp.pl
#!/usr/bin/perl use v5.26; use Data::Dumper; use List::MoreUtils::XS; use List::MoreUtils::PP; my @a = (1,2,3); my @b = (3,1,2); say "List::MoreUtils::XS version is: $List::MoreUtils::XS::VERSION"; say "List::MoreUtils::PP version is: $List::MoreUtils::PP::VERSION"; say "[XS]"; my %cmp = List::MoreUtils::XS::listcmp(@a, @b); my $cmp = List::MoreUtils::XS::listcmp(@a, @b); print Data::Dumper->Dump([\%cmp, $cmp], ['\%cmp', '$cmp']); say "[PP]"; my %cmp = List::MoreUtils::PP::listcmp(@a, @b); my $cmp = List::MoreUtils::PP::listcmp(@a, @b); print Data::Dumper->Dump([\%cmp, $cmp], ['\%cmp', '$cmp']);
Download (untitled) / with headers
text/plain 501b
Dear Henrik, documentation says: Show quoted text
> listcmp ARRAY0 ARRAY1 [ ARRAY2 ... ] > > Returns an associative list of elements and every id of the list it was found in. Allowes easy implementation of @a & @b, @a | @b, @a ^ @b and so on. Undefined entries in any given array are skipped.
The result when reading back a scalar is: undefined. The examples make use of {} and [] to distinguish between hash and array for better understanding, not for interpreting something into an example what might be a wish.
Subject: Re: [rt.cpan.org #132043] listcmp behaviour mismatch (between XS and PP, and to the doc)
Date: Tue, 3 Mar 2020 19:15:39 +0100
To: bug-List-MoreUtils [...] rt.cpan.org
From: Henrik Pauli <henrik.pauli [...] gmail.com>
Download (untitled) / with headers
text/plain 954b
Hi Jens, There is an example of using listcmp in a scalar context in the docs. I pasted both the comment (which might be just simply misleading, as you said), but also the code above, and that code line likely results in nothing that the reader of the docs would expect. On Tue, 3 Mar 2020, 19:00 Jens Rehsack via RT, < bug-List-MoreUtils@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=132043 > > > Dear Henrik, > > documentation says: >
> > listcmp ARRAY0 ARRAY1 [ ARRAY2 ... ] > > > > Returns an associative list of elements and every id of the list it was
> found in. Allowes easy implementation of @a & @b, @a | @b, @a ^ @b and so > on. Undefined entries in any given array are skipped. > > The result when reading back a scalar is: undefined. > > The examples make use of {} and [] to distinguish between hash and array > for better understanding, not for interpreting something into an example > what might be a wish. >
Download (untitled) / with headers
text/plain 1.1k
On Tue Mar 03 13:15:58 2020, ralesk wrote: Show quoted text
> Hi Jens, > > There is an example of using listcmp in a scalar context in the docs.
Thanks for mentioning - I see. This is seriously a documentation bug... Show quoted text
> I > pasted both the comment (which might be just simply misleading, as you > said), but also the code above, and that code line likely results in > nothing that the reader of the docs would expect.
Understood. I will think about in which direction the fix will go ... :) Show quoted text
> On Tue, 3 Mar 2020, 19:00 Jens Rehsack via RT, < > bug-List-MoreUtils@rt.cpan.org> wrote: >
> > <URL: https://rt.cpan.org/Ticket/Display.html?id=132043 > > > > > Dear Henrik, > > > > documentation says: > >
> > > listcmp ARRAY0 ARRAY1 [ ARRAY2 ... ] > > > > > > Returns an associative list of elements and every id of the list it was
> > found in. Allowes easy implementation of @a & @b, @a | @b, @a ^ @b and so > > on. Undefined entries in any given array are skipped. > > > > The result when reading back a scalar is: undefined. > > > > The examples make use of {} and [] to distinguish between hash and array > > for better understanding, not for interpreting something into an example > > what might be a wish. > >
Cheers
Subject: Re: [rt.cpan.org #132043] listcmp behaviour mismatch (between XS and PP, and to the doc)
Date: Tue, 3 Mar 2020 19:24:08 +0100
To: bug-List-MoreUtils [...] rt.cpan.org
From: Henrik Pauli <henrik.pauli [...] gmail.com>
Download (untitled) / with headers
text/plain 1.4k
Thanks :) On Tue, 3 Mar 2020, 19:23 Jens Rehsack via RT, < bug-List-MoreUtils@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=132043 > > > On Tue Mar 03 13:15:58 2020, ralesk wrote:
> > Hi Jens, > > > > There is an example of using listcmp in a scalar context in the docs.
> > Thanks for mentioning - I see. This is seriously a documentation bug... >
> > I > > pasted both the comment (which might be just simply misleading, as you > > said), but also the code above, and that code line likely results in > > nothing that the reader of the docs would expect.
> > Understood. I will think about in which direction the fix will go ... :) >
> > On Tue, 3 Mar 2020, 19:00 Jens Rehsack via RT, < > > bug-List-MoreUtils@rt.cpan.org> wrote: > >
> > > <URL: https://rt.cpan.org/Ticket/Display.html?id=132043 > > > > > > > Dear Henrik, > > > > > > documentation says: > > >
> > > > listcmp ARRAY0 ARRAY1 [ ARRAY2 ... ] > > > > > > > > Returns an associative list of elements and every id of the list it
> was
> > > found in. Allowes easy implementation of @a & @b, @a | @b, @a ^ @b and
> so
> > > on. Undefined entries in any given array are skipped. > > > > > > The result when reading back a scalar is: undefined. > > > > > > The examples make use of {} and [] to distinguish between hash and
> array
> > > for better understanding, not for interpreting something into an
> example
> > > what might be a wish. > > >
> > Cheers > >
XS version patched to behave like PP version and documentation fixed.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.