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?Branislav_Zahradn=C3=ADk?=
Date:
June 8, 2021 19:55
Subject:
Re: RFC: Multiple-alias syntax for for
Message ID:
CAB=rbO=hzZ5+rDthT=pNeNmW-2+8srcX5Ua7cePZdLN=HG2ZFQ@mail.gmail.com
On Tue, 8 Jun 2021 at 13:21, Nicholas Clark <nick@ccl4.org> wrote:

> So, the plan for discussing the proposed RFC process was to feed an idea
> through it, and see how we get from idea to RFC to implementation.
> (Assuming that we don't reject the idea.)
>
> About two months ago Rik had mentioned to me the idea of implementing this
> (currently illegal) syntax to iterate over hashes:
>
>     for my ($key, $value) (%hash) { ... }
>
>
Alternative proposal (as part of more complex proposal I'm preparing, based
on https://gist.github.com/happy-barney/d94d3a6d30b4529ab86ef5ea6c78a043)
Just as code samples

# iterate by two elements, die odd number of numbers
for (@list) {
    has ($key, $value);
}

# iterate by three elements, use default values if @list % 3 != 0
for (@list) {
    has $first;
    has $second := :default => 'foo';
    has $third := :default => 'bar';
}

# iterate over keys only
for (%hash) {
    has $key := :is => HASH::key;
}

# iterate over list with index
for (@list) {
    has $index := :is => ARRAY::index;
    has $value;
}

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