develooper Front page | perl.perl5.porters | Postings from December 2017

Re: Urgent subroutine signatures problems

Thread Previous | Thread Next
Father Chrysostomos
December 14, 2017 04:10
Re: Urgent subroutine signatures problems
Message ID:
Paul Evans wrote:
> Ah; in that case I guess the only real option is to allow :lvalue
> upfront, before the signature then.
>   sub foo :lvalue ($self) { $self->{foo} }

Yes.  I this is my (and Zefram's) preferred syntax, because it
stresses the fact that the signature is actually part of body, just
written shorthand.

I have never understood the objection that it 'looks right' the other
way.  By what standard?  We have a good reason here not simply to copy
C, because a Perl signature and a C signature are completely different
beasts.  And if you want it to look like a sub call, well, it is *not*
a sub call, so why should it look the same?  Also, sub calls never
have attributes, so it cannot look the same, whatever 'the same' would
be.  I am probably arguing against a straw man here....

The vast majority of subs do not use attributes anyway, so it would
not make any difference to most users.

> I wonder, would that look better ordered
>   sub :lvalue foo($self) { $self->{foo} }
> perhaps?

That is already a statement label (sub) followed by a call to lvalue()
with the return value of foo(), ...and then a syntax error.

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