Skip to content

Commit

Permalink
Add trap: prefix minus / method op precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
thundergnat committed Nov 4, 2018
1 parent 001f65c commit 0f2c5c3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions doc/Language/traps.pod6
Expand Up @@ -1038,6 +1038,16 @@ to a power, use parentheses:
say (-1)²; # OUTPUT: «1␤»
say (-1)**2; # OUTPUT: «1␤»
=head2 Method operator calls and prefix minus
Prefix minus binds looser than dotty method op calls. The prefix minus will be
applied to the return value from the method. To ensure the the minus gets
passed as part of the argument, enclose in parenthesis.
=for code
say -1.abs; # OUTPUT: «-1␤»
say (-1).abs; # OUTPUT: «1␤»
=head1 Subroutine and method calls
Subroutine and method calls can be made using one of two forms:
Expand Down

1 comment on commit 0f2c5c3

@zoffixznet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this makes it sound like there's something special about prefix minus, but this precedence setup affects all prefix ops and you can effect a different treatment by detaching the method (only alphanumeric methods can be detached):

say -1 .abs; # OUTPUT: «1␤»

Please sign in to comment.