@@ -11,9 +11,9 @@ its semantic from other routines that accept C<Whatever>-objects as markers
11
11
to do something special. The C < * > literal in term position creates a
12
12
C < Whatever > object.
13
13
14
- Another source of speciality is that the compiler turns
15
- combinations of C < * > in term position and many operators into closures.
16
- This process is called I < Whatever-currying > .
14
+ Much of C < * > 's charm comes from I < Whatever-currying > . When C < * > is used in term
15
+ position in combination with most operators, the compiler will transform the
16
+ expression into a closure of type L < WhateverCode > .
17
17
18
18
my $c = * + 2; # same as -> $x { $x + 2 };
19
19
say $c(4); # 6
@@ -22,17 +22,17 @@ Multiple C<*> in one expression generate closures with as many arguments:
22
22
23
23
my $c = * + *; # same as -> $x, $y { $x + $y }
24
24
25
- C < * > in complex expressions also generate closures:
25
+ Using C < * > in complex expressions will also generate closures:
26
26
27
27
my $c = 4 * * + 5; # same as -> $x { 4 * $x + 5 }
28
28
29
- Calling a method on C < * > also create a closure:
29
+ Calling a method on C < * > also creates a closure:
30
30
31
- say <a b c>.map: *.uc; # A B C
31
+ <a b c>.map: *.uc; # same as <a b c>.map: -> $char { $char.uc }
32
32
33
- Those closure are of type L < WhateverCode > .
34
-
35
- Not all operators and syntactic constructs curry Whatever-stars .
33
+ As mentioned before, not all operators and syntactic constructs curry C < * > (or
34
+ C < Whatever > -stars) to C < WhateverCode > . In the following cases, C < * > will remain
35
+ a C < Whatever > object .
36
36
37
37
= begin table
38
38
@@ -58,15 +58,34 @@ This allow all these constructs to work:
58
58
59
59
.say for 1..*; # infinite loop
60
60
my @a = 1..4;
61
- say @a[1 ..*]; # 2 3 4
62
- say @a[1 ..*-2]; # 2 3
61
+ say @a[0 ..*]; # 1 2 3 4
62
+ say @a[0 ..*-2]; # 1 2 3
63
63
64
- The currying is purely syntactic.
64
+ Because I < Whatever-currying > is a purely syntactic compiler transform, you will get no
65
+ runtime currying of stored C < Whatever > -stars into C < WhateverCode > s.
65
66
66
67
my $x = *;
67
68
$x + 2; # not a closure, dies because
68
69
# it can't coerce $x to Numeric
69
70
71
+ The use cases for stored C < Whatever > -stars are involve those curry-exception
72
+ cases mentioned above. For example, if you want an infinite series by default.
73
+
74
+ my $max = potential-upper-limit() // *;
75
+ my $series = known-lower-limit() ... $max;
76
+
77
+ A stored C < * > will also result in the generation of a C < WhateverCode > in the specific
78
+ case of smart match.
79
+
80
+ my $constraint = find-constraint() // *;
81
+ my $maybe-always-matcher = * ~~ $constraint;
82
+
83
+ If this hypothetical C < find-constraint > were to have found no constraint, C < $maybe-always-matcher >
84
+ would return to C < True > for anything.
85
+
86
+ $maybe-always-matcher(555); # True
87
+ $maybe-always-matcher(Any); # True
88
+
70
89
= head1 Methods
71
90
72
91
= head2 method ACCEPTS
0 commit comments