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

Re: postfix dereference syntax

Thread Previous | Thread Next
From:
Kent Fredric
Date:
July 3, 2013 15:47
Subject:
Re: postfix dereference syntax
Message ID:
CAATnKFBgZDYAWZ+fv0watG0+vQhwyxAxAOg3w1xi_B3Uv0Wm+Q@mail.gmail.com
On 4 July 2013 03:09, Aristotle Pagaltzis <pagaltzis@gmx.de> wrote:
>
> * Dave Mitchell <davem@iabyn.com> [2013-07-03 16:25]:
> > 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->{}.
>
> The same occurred to me just after reading Kent’s mail.
>
> > It's also currently a syntax error in quoted strings, so can easily be
> > used there too:
> >
> >     print "$a->{}bar"
>
> Beautiful!
>

I like it more and more already.  '->[ ]' says far more to me about
dereffing the invocant than ->@ does.

I was thinking that because of the implict bounding of this notation (
the [ ] parens ), you could probably get away with more "weird" syntax
within the [].

And you could possibly entertain the idea of a "*" component inside
it, or something, as a shorthand for a regex-like slicer.

ie:

 ->[]   ==  ->[*]   == ->[qr/.*/]

Which would be intuitive enough for the most part.

 $arry->[*] = @list implies @{$array} = @list
 $arry->[1] = @list implies ( $arry->[1], ) = @list
 $arry->[1,2,3] = @list implies ( $arry->[1], $arry->[2],$arry->[3],) = @list

etc.
And same for hashes

->{} == ->{*} == ->{qr/.*/}  == ->{ grep qr/.*/ keys %$invocant }

Though I don't like special casing too much, ... it could be seen we
could solve this dereferencing problem simply by extending the slice
operators to do our bidding.

--
Kent

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