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

Re: idea: everything-slices

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
June 20, 2021 12:02
Subject:
Re: idea: everything-slices
Message ID:
20210620130150.00336dfc@shy.leonerd.org.uk
On Sat, 19 Jun 2021 21:53:27 -0400
"Ricardo Signes" <perl.p5p@rjbs.manxome.org> 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
interesting.

> %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
arrows?

  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

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

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