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

Re: postfix dereference syntax

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
July 2, 2013 11:41
Subject:
Re: postfix dereference syntax
Message ID:
CAMoYMM-bPHg9parCf1+CZQ3gCN=Gudk2EHs16zu_hdYLQ-7jxQ@mail.gmail.com
On 27 June 2013 03:59, Ricardo Signes <perl.p5p@rjbs.manxome.org> wrote:
>
> We can add postfix syntax for dereferencing to work in *all* places that we
> might dereference, creating a construct that is clearly syntactically an array
> (or hash, etc.) when needed.
>
>   push $x->{foo}->[0]->m->@*, $y;
>
>   push @y, $x->{foo}->[0]->m->@*;
>
>   subroutine( $x->{foo}->[0]->m->@* )
>
>   print $delivery->{email}->body_string_ref->$*;


Also $href->%* I suppose.
Can we talk about failure modes a bit?
A common idiom is to write @{ $foo || [] } in case $foo might be undefined.
Do you remember the conditional-dereference operator that was
bikeshedded to oblivion? ($foo?->bar() was one of the proposed
syntaxes). Can we have this, plus ->@*, plus ?->@* that would expand
to an empty list if its argument is undef?

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


$foo and @foo are interpolated in strings, but not %foo. I suppose
->%* would not either? or maybe just exclude those constructs from
interpolation whatsoever?

>
> Finally, do we need to enable postfix slices?  I think that if we can, we
> should.  I think the syntax is free.
>
>   say for $href->{aref}->@[ 0, 2, 4 ];
>
>   say for $aref->[ $h_idx ]->@{ qw(foo bar baz) };
>
> I think we have a few options for the specific tokens to put after that last
> arrow.  I think $* and @* and so on work well.  Replacing the splat with a
> colon has been suggested as well.  The point here is to provide the feature.
> It's not about reducing total punctuation.  This is Perl, and we must embrace
> our punctuation!  It's about simplifying the reading of code by allowing it to
> be read and written linearly.
>
> --
> 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