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

Re: idea: everything-slices

Thread Previous | Thread Next
Paul "LeoNerd" Evans
June 20, 2021 12:02
Re: idea: everything-slices
Message ID:
On Sat, 19 Jun 2021 21:53:27 -0400
"Ricardo Signes" <> wrote:

> No, this is *not* the same as writing @array or %hash.  For one
> thing, when the \ operator is applied to a slice, it produces a list
> of references to individual elements, not a reference to the
> container.  Similarly, 

As does \(@arr)

  eval: my @arr = (4,5,6); my @refs = \(@arr);  [ @refs ]
  [ \'4', \'5', \'6' ]

(the final [] there just to make it print in "list context")

> @array[*];  # equivalent to @array[ 0 .. $#array ];
> @hash{*};   # equivalent to @hash{ keys %hash };

These two seem borderline unnecessary - as rvalues they are just @array
and %hash. You do point out the way that assigning into @array[*] as an
lvalue won't grow the array - I guess for that usecase it could be

> %hash{*};   # equivalent to %hash{ keys %hash };

Isn't this  values %hash ?

> %array[*];  # equivalent to %array[ 0 .. $#array ];

This one is the only one I can see that appears to add a
sufficiently-useful ability to justify the syntax. It has a certain
neatness if you consider adding the others.

Can we further imagine that these would also be allowed on refs via

  foreach my ($idx, $val) ( $aref->%[*] ) {

That's a 6-symbol punctuation operator.

I remain unconvinced.

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:

  foreach my ($idx, $val) ( enum @array ) { ... }

  foreach my ($idx, $val) ( enum $aref->@* ) { ... }

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

Paul "LeoNerd" Evans      |  |

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About