develooper Front page | perl.perl5.porters | Postings from July 2021

Re: Elevator pitch, deprecating $a/$b sort globals by using sub{}

Thread Previous | Thread Next
From:
Dan Book
Date:
July 5, 2021 21:03
Subject:
Re: Elevator pitch, deprecating $a/$b sort globals by using sub{}
Message ID:
CABMkAVUNL+1QSKLndqM=qcwsf5N6Lg00F10gp-PJw0yxZ9PFkA@mail.gmail.com
On Mon, Jul 5, 2021 at 4:59 PM Oodler 577 via perl5-porters <
perl5-porters@perl.org> wrote:

> * Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> [2021-07-05 20:29:49
> +0100]:
>
> > On Sun, 4 Jul 2021 17:02:00 +0000
> > Nicholas Clark <nick@ccl4.org> wrote:
> >
> > > Our problem here is that sort needs two implicit arguments. *Is* it
> > > the only operator that wants >1 implicit argument?
> >
> > `reduce`
> >
> > as in eg.
> >
> >   my $item = reduce { $a->{$b} } $href, @innerkeys;
>
> What is the meaning of this? I get the words you wrote, but I don't
> understand what you're implying by the hypothetical code example.
> That looks a lot more like a 2-arg C<map>, not a "reduce".
>
> Do you mean something more like,
>
>   my $max = reduce { $a >= $b } @values; # not claiming semantic
> correctness
>
>   my $max = reduce { $a > $b } @values;  # perhaps a 'stable' version
>
> As far as I know a "reduce" results in a single value from many -
> or fewer than the original number...not to lead this off the rails,
> I just don't undertand the point of 'reduce' above.
>

It is an arbitrary mechanism to get a single value from many, yes. In
Paul's example, this single value is a deeply-nested hash key. The function
is available from List::Util, and can be used to implement (less efficient
versions of) many of the other functions in that module.

-Dan

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About