Skip to content
This repository
Browse code

Document [&func] form of infix

  • Loading branch information...
commit 10d772fdfd18869a2b454bc7476c739d9dd32c34 1 parent 7b1a298
Larry Wall authored June 27, 2012

Showing 1 changed file with 26 additions and 2 deletions. Show diff stats Hide diff stats

  1. 28  S03-operators.pod
28  S03-operators.pod
Source Rendered
@@ -14,8 +14,8 @@ Synopsis 3: Perl 6 Operators
14 14
 
15 15
     Created: 8 Mar 2004
16 16
 
17  
-    Last Modified: 16 June 2012
18  
-    Version: 253
  17
+    Last Modified: 27 June 2012
  18
+    Version: 254
19 19
 
20 20
 =head1 Overview
21 21
 
@@ -4864,6 +4864,8 @@ reader, even if not to the compiler:
4864 4864
     @a >>>>> $b        # huh?
4865 4865
     @a >>[>]>> $b      # oh yeah
4866 4866
 
  4867
+=head2 Turning an infix operator into a noun
  4868
+
4867 4869
 Any infix function may be referred to as a noun either by the normal long
4868 4870
 form or a short form using square brackets directly after the C<&> sigil:
4869 4871
 
@@ -4883,6 +4885,28 @@ usually be constructed by applying an operator to C<*>:
4883 4885
 
4884 4886
     sort -*, @list        # sort reversed numerically
4885 4887
 
  4888
+=head2 Turning a binary function into an infix
  4889
+
  4890
+By using the noun form of a binary function inside square brackets,
  4891
+it is possible to turn any function that accepts at least two arguments
  4892
+into an infix operator.  For instance:
  4893
+
  4894
+    $y [&atan2] $x        # same as atan2($y, $x)
  4895
+
  4896
+By itself this may seem relatively useless, but note that it allows
  4897
+composition of normal 2-arg functions with all the infix metaoperators.
  4898
+Since it is primarily intended for composition with metaoperators,
  4899
+this form always assumes a binary function, even if the function could
  4900
+accept more arguments; functions that accept more than 2 arguments do
  4901
+not thereby accept multiple arguments on the right side.  You must use
  4902
+the normal functional form to pass three or more positional arguments.
  4903
+
  4904
+This form of operator is parsed with a precedence of addition.
  4905
+A C<$> is acceptable in place of C<&>, but in either case the
  4906
+next character must be either alphabetic or a left parenthesis.
  4907
+Otherwise a normal infix operator starting with that character will
  4908
+be assumed.  Hence C<[&&]> parses as a form of the C<&&> operator.
  4909
+
4886 4910
 =head1 Declarators
4887 4911
 
4888 4912
 The list of variable declarators has expanded from C<my> and C<our>

0 notes on commit 10d772f

Please sign in to comment.
Something went wrong with that request. Please try again.