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

Re: idea: everything-slices

Thread Previous | Thread Next
From:
Ricardo Signes
Date:
June 20, 2021 12:26
Subject:
Re: idea: everything-slices
Message ID:
aa579e7f-dcf7-47d6-b24a-c1caece5c8ee@beta.fastmail.com
On Sun, Jun 20, 2021, at 8:01 AM, Paul "LeoNerd" Evans wrote:
> > %hash{*};   # equivalent to %hash{ keys %hash };
> 
> Isn't this  values %hash ?

Nope.

  DB<4> %hash = (a => 1, b => 2, c => 3)

  DB<5> x [ %hash{ keys %hash } ]
0  ARRAY(0x7f8a53c60bb0)
   0  'c'
   1  3
   2  'b'
   3  2
   4  'a'
   5  1

That's a pair slice.  Note the use of the % sigil in all caes.  @hash{ keys %hash } would've been the same as values.

> Can we further imagine that these would also be allowed on refs via
> arrows?
> 
>   foreach my ($idx, $val) ( $aref->%[*] ) {
>     ...
>   }

Yes, it must be allowed there for postfix dereference to remain first class.

> Overall, I still feel that it will stomp on less future syntax and be
> "friendlier" if we spelled this "enum" or "enumerate" or somesuch
> keyword, instead:

"kv"

> Perl already has a reputation for being dense punctuation soup - can we
> not make it worse?

I'll admit that this line of argument rarely sways me, but I know other people are more bought in.

-- 
rjbs
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