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

Re: RFC: Multiple-alias syntax for for

Thread Previous | Thread Next
From:
=?UTF-8?Q?Salvador_Fandi=c3=b1o?=
Date:
June 10, 2021 12:05
Subject:
Re: RFC: Multiple-alias syntax for for
Message ID:
20210610120511.29533.qmail@lists-nntp.develooper.com
On 10/6/21 10:48, Paul "LeoNerd" Evans wrote:
> On Thu, 10 Jun 2021 08:27:54 +0000
> Nicholas Clark <nick@ccl4.org> wrote:
> 
>> Not with *that* syntax, because that conflicts with general
>> n-at-a-time.
>>
>> But it's a problem that needs solving well, and I hope there will be
>> an RFC about it soon.
> 
> I've often pondered stealing Python's "enumerate" function; so that
> would be
> 
> 
>    foreach my ($index, $item) (enumerate @array)
>    {
>      ...
>    }
> 
> Where `enumerate LIST` just yields (0, LIST[0], 1, LIST[1], ...)
> 

This is probably going out of control but...

How about extending "for" with attributes?

   for :enumerate my ($index, $item) (@a) { ... }

   for :take(4) my (@b) (@a) { ... }

   for my ($key, $val) (%hash) {
     # implicit :take(2) ?
   }

   for :enumerate ($ix, $key, $val) (%hash) { ... }

   for :enumerate :take(4) my ($ix, $foo, $bar) (@a) {
     # note that 2 values are discarded
     # in every iteration

   }


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