develooper Front page | perl.perl5.porters | Postings from May 2023

Re: Limitations of Attributes

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
May 5, 2023 12:49
Subject:
Re: Limitations of Attributes
Message ID:
20230505134845.539d894d@shy.leonerd.org.uk
On Fri, 5 May 2023 11:58:56 +0100
Dave Mitchell <davem@iabyn.com> wrote:

> Note that in Perl 6 and some CPAN signature modules, the 'method'
> keyword declares an implicit $self parameter, whose name can be
> overridden using a postfix ':':
> 
>     method foo($x, $y)      { $self->{$x} = $y }  # implicit $self
>     method foo($me: $x, $y) {   $me->{$x} = $y }  # explicit invocant
> 
> I have no plans to introduce such a 'method' keyword, but if we did,
> we might need different syntax for the invocant, as the ':' would be
> interpreted as the start of an attribute unless the toker was clever
> and we are very careful that all signature syntax is capable of being
> disambiguated.

A quick note on that part - the newly-added `method` keyword doesn't
allow you to rename the invocant variable at all. You just get `$self`,
so there's no such syntax ambiguity here to worry about.

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