develooper Front page | perl.perl6.users | Postings from August 2020

Seq whitespace sensitivity? (was Re: print particular linesquestion)

Thread Next
From:
William Michels via perl6-users
Date:
August 26, 2020 16:42
Subject:
Seq whitespace sensitivity? (was Re: print particular linesquestion)
Message ID:
CAA99HCym-GzOKVnJ2=qYvbxW-fWeyBnqmnUpQLFk9pJo4zAq3A@mail.gmail.com
> They can be pretty great, especially when combined with the magic op= operators that (in essence) know about identity elements.  I've done a few challenges on the Code Golf Stackexchange site where I wanted an infinite sequence like this:
>
>     0, 1, -2, 3, -4, 5, -6, ...
>
> It took me a while to realize this can be expressed in Raku simply as:
>
>     { $++ * ($ *= -1) } ... *
>

Hi Sean, that's a neat solution! I seem to have found an oddity though
(whitespace sensitivity). In the REPL:

> say { $++ * ($ *= -1) } ...21
(0 1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -16 17 -18 19 -20 21)
> say { $++ * ($ *= -1) } ...^21
(0 1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -16 17 -18 19 -20)
> say { $++ * ($ *= -1) } ... 21
(0 1 -2 3 -4 5 -6 7 -8 9 -10 11 -12 13 -14 15 -16 17 -18 19 -20 21)
> say { $++ * ($ *= -1) } ... ^21
(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)

I would have expected the last line of code (whitespace between "..."
and "^21") to give the same answer as the first three. Any ideas?

Best, Bill.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About