Skip Menu |
 

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

Report information
The Basics
Id: 50656
Status: rejected
Priority: 0/
Queue: Scalar-List-Utils

People
Owner: Nobody in particular
Requestors: pollux [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Closure-friendly List::Util::reduce()
Download (untitled) / with headers
text/plain 351b
I would like to be able to do the following: my @f = ( sub { "a" }, sub { "b" }, sub { "c" }, sub { "d" }, sub { "e" }, ); my $f = reduce { sub { $a->() . $b->() } } ( sub { '' }, @f ); Of course, $f->() should return 'abcde'. Is there a way to do this currently or is it possible to modify reduce for this?
Subject: Re: [rt.cpan.org #50656] Closure-friendly List::Util::reduce()
Date: Mon, 19 Oct 2009 13:44:14 -0500
To: bug-Scalar-List-Utils [...] rt.cpan.org
From: Graham Barr <gbarr [...] pobox.com>
Download (untitled) / with headers
text/plain 631b
On Oct 19, 2009, at 12:40 PM, Paul Sandulescu via RT wrote: Show quoted text
> > I would like to be able to do the following: > > my @f = ( > sub { "a" }, > sub { "b" }, > sub { "c" }, > sub { "d" }, > sub { "e" }, > ); > > my $f = reduce { sub { $a->() . $b->() } } ( sub { '' }, @f ); > > Of course, $f->() should return 'abcde'.
nope. $a and $b are global and you are returning a sub so $a and $b are not resolved until the sub is run you could do my $f = reduce { my $c = $a->() . $b->(); sub { $c } } ( sub { '' }, @f ); which will cause $a->() and $b->() to be called during the reduce. Graham.


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.