@@ -88,41 +88,42 @@ As an example:
88
88
89
89
my $p = Range.new( 3, 5 );
90
90
my $r = Range.new( 1, 10 );
91
- $p.ACCEPTS( $r ); # False
92
- $r.ACCEPTS( $p ); # True
93
- $r ~~ $p; # False (same as $p.ACCEPTS( $r )
94
- $p ~~ $r; # True (same as $r.ACCEPTS( $p )
91
+
92
+ say $p.ACCEPTS( $r ); # OUTPUT: «False»
93
+ say $r.ACCEPTS( $p ); # OUTPUT: «True»
94
+ say $r ~~ $p; # OUTPUT: «False» (same as $p.ACCEPTS( $r )
95
+ say $p ~~ $r; # OUTPUT: «True» (same as $r.ACCEPTS( $p )
95
96
96
97
Of course, an infinite C < Range > always contains another C < Range > , therefore:
97
98
98
- 1..10 ~~ -∞..∞; # True
99
- 1..10 ~~ -∞^..^∞; # True
99
+ say 1..10 ~~ -∞..∞; # OUTPUT: « True»
100
+ say 1..10 ~~ -∞^..^∞; # OUTPUT: « True»
100
101
101
102
Similarly, a C < Range > with open boundaries often includes other ranges:
102
103
103
- 1..2 ~~ *..10; # True
104
- 2..5 ~~ 1..*; # True
104
+ say 1..2 ~~ *..10; # OUTPUT: « True»
105
+ say 2..5 ~~ 1..*; # OUTPUT: « True»
105
106
106
107
107
108
It is also possible to use non-numeric ranges, for instance string based
108
109
ones:
109
110
110
- 'a'..'j' ~~ 'b'..'c'; # False
111
- 'b'..'c' ~~ 'a'..'j'; # True
112
- 'perl' ~~ -∞^..^∞; # True
113
- 'perl' ~~ -∞..∞; # True
114
- 'perl' ~~ 1..*; # True
111
+ say 'a'..'j' ~~ 'b'..'c'; # OUTPUT: « False»
112
+ say 'b'..'c' ~~ 'a'..'j'; # OUTPUT: « True»
113
+ say 'perl' ~~ -∞^..^∞; # OUTPUT: « True»
114
+ say 'perl' ~~ -∞..∞; # OUTPUT: « True»
115
+ say 'perl' ~~ 1..*; # OUTPUT: « True»
115
116
116
117
117
118
When smart-matching a C < Range > of integers with a L < Cool > (string)
118
119
the C < ACCEPTS > methods exploits the L < before|/routine/before >
119
120
and L < after|/routine/after > operators in order to check that
120
121
the C < Cool > value is overlapping the range:
121
122
122
- 1.10 ~~ '5'; # False
123
- '5' before 1; # False
124
- '5' after 10; # True
125
- '5' ~~ *..10; # False
123
+ say 1.10 ~~ '5'; # OUTPUT: « False»
124
+ say '5' before 1; # OUTPUT: « False»
125
+ say '5' after 10; # OUTPUT: « True»
126
+ say '5' ~~ *..10; # OUTPUT: « False»
126
127
127
128
In the above example, since the C < '5' > string is I < after > the C < 10 > integer value,
128
129
the C < Range > does not overlap with the specified value.
0 commit comments