> On 10 Oct 2016, at 14:22, Luca Ferrari <fluca1...@infinito.it> wrote:
> 
> Hi all,
> I'm misunderstanding the ... operator. The following works as expected:
> 
>    @seq = ( 1, 2, -> $a, $b { $a * 2 + $b % 2 } ... * )[^10];
> 
> while the following seems to loop infinitely:
> 
>    @seq = ( 1, 2, -> $a, $b { $a * 2 + $b % 2 } ... 10 );
> 
> Looking at <https://docs.perl6.org/language/operators#infix_...> I
> cannot find an explaination of why the ending value of 10 is not
> honored in the second case.

If you’re using a Callable in the sequence operator, the end-point needs to 
match exactly:

$ 6 'say 1,4, { $^a + 3 } ... 10'
(1 4 7 10)

6 'say 1,4, { $^a + 3 } ... 11'
(1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 
82 85 88 91 94 97 100 103 106 109 112 115 118 121 124 127 130 133 136 139 142 
145 148 151 154 157 160 163 166 169 172 175 178 181 184 187 190 193 196 199 202 
205 208 211 214 217 220 223 226 229 232 235 238 241 244 247 250 253 256 259 262 
265 268 271 274 277 280 283 286 289 292 295 298 …)

The reason for it is because you *could* be devising a sequence that may 
actually exceed the end value temporarily:

$ 6 'say 1,4, { $^a > 10 ?? $^a - 1 !! $^a + 3 } ... 11'
(1 4 7 10 13 12 11)

It is explained here: 
https://docs.perl6.org/language/operators#index-entry-sequence_operator

Hope this helps.



Liz

Reply via email to