develooper Front page | perl.perl5.porters | Postings from July 2013

Re: postfix dereference syntax

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
July 3, 2013 14:23
Subject:
Re: postfix dereference syntax
Message ID:
20130703142320.GD2063@iabyn.com
On Wed, Jun 26, 2013 at 09:59:02PM -0400, Ricardo Signes wrote:
>   push @y, $x->{foo}->[0]->m->@*;

> If we want the two forms to be really of equivalent value, we'll also need to
> be concerned with:
> 
>   print "Things: $aref_of_things->@*"
> 
> ...which gets into less clearly-introduceable behavior.


Alternatively, what about instead of expr->@*, we use

    expr->[]?

This is currently a syntax error. It has the mnemonic of a list slice
that contains all elements. Ditto expr->{}.

It's also currently a syntax error in quoted strings, so can easily be used
there too:

    print "$a->{}bar"

It could conceivably be expanded to indicate slicing, such as

    $a->[1,5,7]

*except* that this is currently valid syntax, where the list of indices is 
evaluated in scalar context, which discards all but the last element. So
the above is currently equivalent to

    $a->[7]

Potentially we could deprecate the current behaviour, then (if it turns
out not to be commonly used), repurpose it. This would also allow slices
in strings, e.g. "$a->[1,5,7]", which also currently evaluates to
"$a->[7]".

-- 
I thought I was wrong once, but I was mistaken.

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