Skip Menu |
Report information
Id: 131652
Status: resolved
Priority: 0/
Queue: perl5

Owner: jkeenan <jkeenan [at] cpan.org>
Requestors: kes-kes [at] yandex.ru
Cc:
AdminCc:

Operating System: Linux
PatchStatus: HasPatch
Severity: low
Type: docs
Perl Version: 5.27.2
Fixed In: (no value)

Attachments


Subject: 'map' returns array instead of list
To: perlbug <perlbug [...] perl.org>
Date: Sun, 25 Jun 2017 15:05:00 +0300
From: KES <kes-kes [...] yandex.ru>
Download (untitled) / with headers
text/plain 4.2k
To: perlbug@perl.org Subject: 'map' returns array instead of list From: kes-kes@yandex.ru Message-Id: <5.24.1_27793_1498391820@kes-X751SA> Cc: kes-kes@yandex.ru Reply-To: kes-kes@yandex.ru This is a bug report for perl from kes-kes@yandex.ru, generated with the help of perlbug 1.40 running under perl 5.24.1. ----------------------------------------------------------------- [Please describe your issue here] The [DOC](https://perldoc.perl.org/functions/map.html) says: map ... evaluates ... and returns the list value but it returns array: $x = ( 1, 7, 5 ); #5 list: last element is returned print $x; @array = ( 1, 7, 5 ); $x = @array; #3 array: number of elements is returned print $x; $x = map{ $_ } ( 1, 7, 5 ); #EXPECTED: 5 (list), ACTUAL: 3 (array) print $x; OUTPUT is: 533 [Please do not change anything below this line] ----------------------------------------------------------------- --- Flags: category=core severity=medium --- Site configuration information for perl 5.24.1: Configured by kes at Sun Apr 30 22:40:30 EEST 2017. Summary of my perl5 (revision 5 version 24 subversion 1) configuration: Platform: osname=linux, osvers=4.4.0-53-generic, archname=x86_64-linux uname='linux kes-x751sa 4.4.0-53-generic #74-ubuntu smp fri dec 2 15:59:10 utc 2016 x86_64 x86_64 x86_64 gnulinux ' config_args='-de -Dprefix=/home/kes/perl5/perlbrew/perls/perl-5.24.1 -Aeval:scriptdir=/home/kes/perl5/perlbrew/perls/perl-5.24.1/bin' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include' ccversion='', gccversion='5.4.0 20160609', gccosandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='cc', ldflags =' -fstack-protector-strong -L/usr/local/lib' libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc libc=libc-2.23.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.23' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong' Locally applied patches: Devel::PatchPerl 1.38 --- @INC for perl 5.24.1: /home/kes/perl5/perlbrew/perls/perl-5.24.1/lib/site_perl/5.24.1/x86_64-linux /home/kes/perl5/perlbrew/perls/perl-5.24.1/lib/site_perl/5.24.1 /home/kes/perl5/perlbrew/perls/perl-5.24.1/lib/5.24.1/x86_64-linux /home/kes/perl5/perlbrew/perls/perl-5.24.1/lib/5.24.1 --- Environment for perl 5.24.1: HOME=/home/kes LANG=en_US.UTF-8 LANGUAGE=en LC_ADDRESS=uk_UA.UTF-8 LC_IDENTIFICATION=uk_UA.UTF-8 LC_MEASUREMENT=uk_UA.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_MONETARY=uk_UA.UTF-8 LC_NAME=uk_UA.UTF-8 LC_NUMERIC=uk_UA.UTF-8 LC_PAPER=uk_UA.UTF-8 LC_TELEPHONE=uk_UA.UTF-8 LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/kes/perl5/perlbrew/bin:/home/kes/perl5/perlbrew/perls/perl-5.24.1/bin:/home/kes/bin:/home/kes/bin:/home/kes/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games PERLBREW=command perlbrew PERLBREW_BASHRC_VERSION=0.78 PERLBREW_HOME=/home/kes/.perlbrew PERLBREW_MANPATH=/home/kes/perl5/perlbrew/perls/perl-5.24.1/man PERLBREW_PATH=/home/kes/perl5/perlbrew/bin:/home/kes/perl5/perlbrew/perls/perl-5.24.1/bin PERLBREW_PERL=perl-5.24.1 PERLBREW_ROOT=/home/kes/perl5/perlbrew PERLBREW_VERSION=0.78 PERL_BADLANG (unset) SHELL=/bin/bash
To: Perl5 Porters <perl5-porters [...] perl.org>
Subject: Re: [perl #131652] 'map' returns array instead of list
CC: bugs-bitbucket [...] rt.perl.org
From: Eirik Berg Hanssen <Eirik-Berg.Hanssen [...] allverden.no>
Date: Sun, 25 Jun 2017 14:23:21 +0200
Download (untitled) / with headers
text/plain 1.2k

On Sun, Jun 25, 2017 at 2:06 PM, KES <perlbug-followup@perl.org> wrote:
Show quoted text
The [DOC](https://perldoc.perl.org/functions/map.html) says:

map ... evaluates ...  and returns the list value

  … and goes on to say "In scalar context, returns the total number of elements so generated".
 
Show quoted text

but it returns array:

$x =  ( 1, 7, 5 );            #5  list: last element is returned
print $x;

  Nope; this is the comma operator in scalar context, returning the RHS operand.
(Bugbear mantra: There's no such thing as a list in scalar context – only expressions are evaluated in different contexts.)

Show quoted text
@array =  ( 1, 7, 5 );
$x =  @array;                 #3  array: number of elements is returned
print $x;

$x =  map{ $_ } ( 1, 7, 5 );  #EXPECTED: 5 (list), ACTUAL: 3 (array)
print $x;

  Since map in scalar context is documented to return the "total number of elements so generated", 3 is to be expected.

  Works as per documentation – no bug, just my particular bugbear, the idea of lists in scalar context.

  At most I might suggest making the documentation clearer that the return value is context dependent, so that instead of the seemingly unconditional "returns the list value composed of", we explicate the context: "in list context returns the value composed of".


Eirik
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 1.5k
On Sun, 25 Jun 2017 05:23:34 -0700, Eirik-Berg.Hanssen@allverden.no wrote: Show quoted text
> On Sun, Jun 25, 2017 at 2:06 PM, KES <perlbug-followup@perl.org> wrote: >
> > The [DOC](https://perldoc.perl.org/functions/map.html) says: > > > > map ... evaluates ... and returns the list value > >
> > … and goes on to say "In scalar context, returns the total number of > elements so generated". > >
> > > > but it returns array: > > > > $x = ( 1, 7, 5 ); #5 list: last element is returned > > print $x; > >
> > Nope; this is the comma operator in scalar context, returning the RHS > operand. > (Bugbear mantra: There's no such thing as a list in scalar context – only > expressions are evaluated in different contexts.) > > @array = ( 1, 7, 5 );
> > $x = @array; #3 array: number of elements is returned > > print $x; > > > > $x = map{ $_ } ( 1, 7, 5 ); #EXPECTED: 5 (list), ACTUAL: 3 (array) > > print $x; > >
> > Since map in scalar context is documented to return the "total number of > elements so generated", 3 is to be expected. > > Works as per documentation – no bug, just my particular bugbear, the idea > of lists in scalar context. > > At most I might suggest making the documentation clearer that the return > value is context dependent, so that instead of the seemingly unconditional > "returns the list value composed of", we explicate the context: "in list > context returns the value composed of".
Or what about we eschew ‘value’ and say ‘a list composed of...’? -- Father Chrysostomos
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 1.7k
On Sun, 25 Jun 2017 13:08:41 GMT, sprout wrote: Show quoted text
> On Sun, 25 Jun 2017 05:23:34 -0700, Eirik-Berg.Hanssen@allverden.no > wrote:
> > On Sun, Jun 25, 2017 at 2:06 PM, KES <perlbug-followup@perl.org> > > wrote: > >
> > > The [DOC](https://perldoc.perl.org/functions/map.html) says: > > > > > > map ... evaluates ... and returns the list value > > >
> > > > … and goes on to say "In scalar context, returns the total number of > > elements so generated". > > > >
> > > > > > but it returns array: > > > > > > $x = ( 1, 7, 5 ); #5 list: last element is returned > > > print $x; > > >
> > > > Nope; this is the comma operator in scalar context, returning the RHS > > operand. > > (Bugbear mantra: There's no such thing as a list in scalar context – > > only > > expressions are evaluated in different contexts.) > > > > @array = ( 1, 7, 5 );
> > > $x = @array; #3 array: number of elements is > > > returned > > > print $x; > > > > > > $x = map{ $_ } ( 1, 7, 5 ); #EXPECTED: 5 (list), ACTUAL: 3 > > > (array) > > > print $x; > > >
> > > > Since map in scalar context is documented to return the "total number > > of > > elements so generated", 3 is to be expected. > > > > Works as per documentation – no bug, just my particular bugbear, the > > idea > > of lists in scalar context. > > > > At most I might suggest making the documentation clearer that the > > return > > value is context dependent, so that instead of the seemingly > > unconditional > > "returns the list value composed of", we explicate the context: "in > > list > > context returns the value composed of".
> > Or what about we eschew ‘value’ and say ‘a list composed of...’?
Please review the patch attached. Thank you very much. -- James E Keenan (jkeenan@cpan.org)
Subject: 131652-0001-Improve-documentation-of-map.patch
From f6d32eb695407668bf1f7b5973029574a84b31f2 Mon Sep 17 00:00:00 2001 From: James E Keenan <jkeenan@cpan.org> Date: Fri, 7 Jul 2017 19:59:47 -0400 Subject: [PATCH] Improve documentation of 'map'. Per discussion in RT # 131652. --- pod/perlfunc.pod | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index b1e4ac2..dadb3d0 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -4071,12 +4071,11 @@ X<map> =for Pod::Functions apply a change to a list to get back a new list with the changes Evaluates the BLOCK or EXPR for each element of LIST (locally setting -L<C<$_>|perlvar/$_> to each element) and returns the list value composed -of the -results of each such evaluation. In scalar context, returns the -total number of elements so generated. Evaluates BLOCK or EXPR in -list context, so each element of LIST may produce zero, one, or -more elements in the returned value. +L<C<$_>|perlvar/$_> to each element) and composes a list of the results of +each such evaluation. Each element of LIST may produce zero, one, or more +elements in the generated list, so the number of elements in the generated +list may differ from that in LIST. In scalar context, returns the total +number of elements so generated. In list context, returns the generated list. my @chars = map(chr, @numbers); -- 2.7.4
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 119b
On Fri, 07 Jul 2017 17:02:05 -0700, jkeenan wrote: Show quoted text
> Please review the patch attached.
+one -- Father Chrysostomos
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 380b
On Sat, 08 Jul 2017 01:28:06 GMT, sprout wrote: Show quoted text
> On Fri, 07 Jul 2017 17:02:05 -0700, jkeenan wrote:
> > Please review the patch attached.
> > +one >
P5P: Any further comments on this documentation patch? I am taking this ticket for the purpose of applying the patch within 7 days unless there is a valid objection. Thank you very much. -- James E Keenan (jkeenan@cpan.org)
Date: Mon, 17 Jul 2017 12:18:12 -0500
From: David Nicol <davidnicol [...] gmail.com>
CC: Perl 5 Porters <perl5-porters [...] perl.org>
To: follup <perlbug-followup [...] perl.org>
Subject: Re: [perl #131652] 'map' returns array instead of list
Download (untitled) / with headers
text/plain 202b
this is a fine example of how "array" and "list" appear to be used interchangeably in the documentation.

that said I think the patch is great.

--
everything has to be just so or the magic won't work
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 569b
On Tue, 11 Jul 2017 14:50:23 GMT, jkeenan wrote: Show quoted text
> On Sat, 08 Jul 2017 01:28:06 GMT, sprout wrote:
> > On Fri, 07 Jul 2017 17:02:05 -0700, jkeenan wrote:
> > > Please review the patch attached.
> > > > +one > >
> > P5P: Any further comments on this documentation patch? > > I am taking this ticket for the purpose of applying the patch within 7 > days unless there is a valid objection. > > Thank you very much.
Applied to blead in commit e1d354993802640ccfdfb4949cc8dc3ae14db4f; marking ticket Resolved. Thank you very much. -- James E Keenan (jkeenan@cpan.org)


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

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org