in reply to Re: [Raku] Ranges in array slices in thread [Raku] Ranges in array slices
Thanks tomasz, and a belated welcome to the Monastery!
The sequence operator looks really powerful: my attention was particularly caught by this example from the documentation:
This allows you to write
say 1, 1, * + * ...^ *>= 100;
# OUTPUT: «(1 1 2 3 5 8 13 21 34 55 89)»
to generate all Fibonacci numbers up to but excluding 100.
Of course, now that I have an operator that works the way I expected the range operator to work, I’m wondering: why would I ever need the range operator?
Cheers,
Re^3: [Raku] Ranges in array slices
by holli (Abbot) on Jun 05, 2021 at 19:14 UTC
|
| [reply] [d/l] [select] |
Re^3: [Raku] Ranges in array slices
by tomasz (Acolyte) on Jun 05, 2021 at 16:11 UTC
|
Hi there!
I'm not so sure, to be honest. I'm still very fresh with Raku.
From what I've gathered so far, you'll take range when you just need two ends of a stick, and sequence, when you need the stick.
EDIT:
Sequence can also be characterised by the accented stickiness of the stick, to continue this sticky metaphor. It's accented even over the idea of its end, to the effect that if an end of the stick doesn't meet the stickiness, then it's ignored. Example:
0, * + 2 ... 1
See, where it goes?
I wonder if it's grammatically possible to jump over both ends this way... (sic!)1
1) ...like this... | [reply] [d/l] |
|
| [reply] [d/l] [select] |
|
To make sure, we're on the same page, the sequence of even numbers can end:
> say 0, * + 2 ... $_ for 2, 10
(0 2)
(0 2 4 6 8 10)
And if this was obvious, then - yes, that's the point. Sequences allow this kind of dissonances. No error is reported by the language. There's space for absurd. Or what should this be better called? | [reply] [d/l] |
|
|
|
I think we all agree here on what's what and there's no point to argue about. I'll however continue my line of thinking just as a lighthearted musing.
It's a language feature and so if there is an error, it will be a semantic error. Or possibly not, as this feature can be productively exploited.
For example, let's take a hard to calculate number N and use it as the last element condition. And for the generator function let's use a G, and some S for the starting point. Here' the formula:
S, G ... N
So we're testing N against G for S. As the test duration can explode towards infinity, we need to limit the number of steps or the time of our test. Let's name this limitation "<<< L" in pseudocode:
S, G ... N <<< L
If the test doesn't end before L, we could consider this a proof of absurdity (or semantic errorness) of "S, G ... N" relative to L. And isn't this absurdity similar to infinity of N? Couldn't we say N is infinite relative to S, G, L?
EDIT: This would be valid for easily computable Ns also. We could say: 1 is infinite relative to 0, * + 2, any L. | [reply] [d/l] [select] |
|
|
|
|