You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new syntax (which uses the ! twigil) is an attempt toward unified syntax.
The ! twigil is used in classes for private data members and methods:
classFoo {
has$!priv_member;
sub!priv_method() {say"In Foo!priv_method()"}
}
with Foo.new( ) { .!priv_method; } # In Foo!priv_method()
Why disallow the use of the shorthand syntax just because !priv_meth( ) doesn't work as expected? The Perl (6) language is designed to fit the needs of its users. This is a fix to do just that while providing expected functionality and uniformity.
The text was updated successfully, but these errors were encountered:
It is not possible to declare private subroutines, only private methods are allowed:
$ perl6 -e 'class A { sub !foo { } };'
===SORRY!=== Error while compiling -e
Missing block
It is not possible to call private method outside of class the way you wrote it:
$ perl6 -e 'class A { method !foo { } }; my $a = A.new; $a!foo'
===SORRY!=== Error while compiling -e
Private method call to foo must be fully qualified with the package containing the method
Proper way is to use fully qualified package name AND trust policy:
$ perl6 -e 'class A { trusts GLOBAL; method !foo { } }; my $a = A.new; $a!A::foo'
So your shortcut would look like:
with Foo.new( ) { .!Foo::priv_method; }
And that destroys whole "shorthand" concept, because you cannot rely solely on $_ type.
On Method Calls, it is noted that dot natation can be used to omit the $_ if the object which is being called is already in the $_ variable.
However, it is illegal to use the private method sigil (
!
) for short calls:New Syntax (Addition)
I propose a change to the Perl 6 syntax/grammar which allows a shorthand for the calling of private methods while the object is in $_:
.!priv
Why?
The new syntax (which uses the
!
twigil) is an attempt toward unified syntax.The
!
twigil is used in classes for private data members and methods:Why disallow the use of the shorthand syntax just because
!priv_meth( )
doesn't work as expected? The Perl (6) language is designed to fit the needs of its users. This is a fix to do just that while providing expected functionality and uniformity.The text was updated successfully, but these errors were encountered: