New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
「my @a = 1 … 9999999」 is not lazy, explain it somewhere #1103
Comments
Ah, another thing to note is that this is actually lazy:
Also, some discussion: https://irclog.perlgeek.de/perl6/2017-01-02#i_13836946 |
👍 |
|
Is there a minimum number for which a Seq turns eager? Is that maybe in the Rakudo code? |
Minimum number? No. |
Well, the documentation says it produces lazy lists. I guess that's all wrong. |
There are a few tests in |
FWIW
|
Lazy lists are only generated by … if the endpoint is infinity. I just
changed that in the documentation. Please check that it's correct now. It
was simply wrong in the initial description.
|
No-no that's not really closed. Here are some ramblings.
It's not about the size, it is always as lazy as possible. The difference between Inf and non-Inf endpoint seems to be that it's just special-cased differently. I have no idea how to explain this, but as far as I can understand So basically I guess I don't know what a Seq is, and how it's different (if it is) from a List thingie. As for |
I have described it according to the roast tests, which only return lazy
sequences if the endpoint is */Inf. Please check out the new description,
flag what's wrong and change the issue accordingly, because according to
the roast test, 1 … 9999999 should never be lazy.
|
Still not right, it doesn't matter if the endpoint is Inf or not, everything will be generated on demand. Try something like this maybe to see it: |
My 2¢: use term "lazy" less. It's really adds a lot of confusion as it can mean "values generated on-demand" (as opposed to right-away) and all of our Seqs are like that, and it can also mean "infinite-like", which is what .is-lazy flag represents. Generally, infinite-like Seqs are meant to be treated as if they're infinite because trying to reify them right away would be bad (i.e. with actual infinite Seqs, that'd mean consuming all CPU;
Here's an example that shows this. The first Seq has a
You can also force non-infinite-like Seqs to be treated as infinite-like with the
And you can see that it's the assignment to
"assigned" is printed before any values were generated. |
2018-04-20 18:39 GMT+02:00 Zoffix Znet <notifications@github.com>:
My 2¢: use term "lazy" less.
It's really adds a lot of confusion as it can mean "values generated
on-demand" (as opposed to right-away) and all of our Seqs are like that,
and it can also mean "infinite-like", which is what .is-lazy flag
represents.
- The … always produces Seq that produce values on-demand
- Assignment to @ is "mostly-eager" and will reify Seqs immediately,
unless they're infinite-like, in which case it'll reify them only on-demand
But assignment is outside the scope of this particular issue and paragraph.
Such as it is now, it does avoid mentioning "lazy" in favor of "on
demand".
Here's an example that shows this. The first Seq has a * endpoint, so
it's infinite-like (marked as .is-lazy) and you can see assigned is
printed before reifying: The second Seq only goes up to 3 so it's not
infinite-like and the assignment reifies it right away,
$ perl6 -e 'my @A = {say "reifying"; ++$} … *; say "assigned"; say @A[^2]'
assigned
reifying
reifying
(1 2)
$ perl6 -e 'my @A = {say "reifying"; ++$} … 3; say "assigned"; say @A[^2]'
reifying
reifying
reifying
assigned
(1 2)
You can also force non-infinite-like Seqs to be treated as infinite-like
with the lazy routine call:
$ perl6 -e 'my @A = lazy ({say "reifying"; ++$} … 3); say "assigned"; say @A[^2]'
assigned
reifying
reifying
(1 2)
And you can see that it's the assignment to @ var that causes immediate
reification of non-infinite-like Seqs and that they normally produce values
on-demand with this example:
my $s := ({say "reifying"; ++$} … 3); say "assigned"; say $s[^2]'
assigned
reifying
reifying
(1 2)
"assigned" is printed before any values were generated.
Maybe add "reification" to glossary and/or something to the traps page.
|
It (or a form of it) is already there: https://docs.perl6.org/language/glossary#Reify |
I didn't know that page was also affected... |
Anyway, if no further work is needed on this particular issue, allow me to close it if you don't want to change the title or repurpose it for something else. |
This is a continuation of RT #130480.
Our docs say:
Well, is it? Seems like it produces
Seq
-s, not lazy lists. Lazy lists can be obtained, for example, from.list
-ing a Range (..
operator, not...
), or bylazy
-ing a Seq.And getting back to the ticket:
↑ This is not lazy at all. But with our current documentation it is fair to assume that it should be lazy.
We should improve our docs on
…
first. Then perhaps document another trap?The text was updated successfully, but these errors were encountered: