Skip to content
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

Returning lazy lists from a start { } block results in empty list #3505

Closed
p6rt opened this issue Sep 6, 2014 · 5 comments
Closed

Returning lazy lists from a start { } block results in empty list #3505

p6rt opened this issue Sep 6, 2014 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Sep 6, 2014

Migrated from rt.perl.org#122715 (status was 'resolved')

Searchable as RT122715$

@p6rt
Copy link
Author

p6rt commented Sep 6, 2014

From @moritz

<moritz> m​: my @​outer = 0..3; await my $x = start { eager @​outer.map​:
*+1 }; say $x.result.perl
<camelia> rakudo-moar 4a7429​: OUTPUT«(1, 2, 3, 4).list␤»
<moritz> m​: my @​outer = 0..3; await my $x = start { @​outer.map​: *+1 };
say $x.result.perl
<camelia> rakudo-moar 4a7429​: OUTPUT«().list␤»

Same result on the JVM.

I guess this is related to the generator being scheduled on the old
thread that has already terminated, or something like this.

Anyway, it shouldn't silently swallow the contents of a lazy list.

@p6rt
Copy link
Author

p6rt commented Sep 6, 2014

From @moritz

Fudged tests are in t/spec/S17-promise/start.t

@p6rt
Copy link
Author

p6rt commented Oct 28, 2015

From @jnthn

On Sat Sep 06 06​:31​:08 2014, moritz wrote​:

<moritz> m​: my @​outer = 0..3; await my $x = start { eager @​outer.map​:
*+1 }; say $x.result.perl
<camelia> rakudo-moar 4a7429​: OUTPUT«(1, 2, 3, 4).list␤»
<moritz> m​: my @​outer = 0..3; await my $x = start { @​outer.map​: *+1 };
say $x.result.perl
<camelia> rakudo-moar 4a7429​: OUTPUT«().list␤»

Same result on the JVM.

I guess this is related to the generator being scheduled on the old
thread that has already terminated, or something like this.

Anyway, it shouldn't silently swallow the contents of a lazy list.

After the GLR, it whined about the Seq already having been iterated. I've now fixed that (turns out Promise!keep was actually sinking the Seq). Note that it's important to use the value that comes back from await, *not* to have the await in sink context and then call .result. Why? Because then you end up sinking the thing that await hands back.

So, this (after my fix) is now fine​:

my @​outer = 0..3; say await start { @​outer.map​: *+1 }

This even with my fix isn't (by design) going to work​:

my @​outer = 0..3;
my $p = start { @​outer.map​: *+1 };
await $p; # sinks the result
say $p.result; # Seq already consumed by the sink above

Since a Seq is one-shot. You can create this situation easily enough without Promises being involved, however - that's the nature of Seq.

Corrected tests unfuged in S17-promise/start.t, and added another one golfed from an example on IRC.

@p6rt
Copy link
Author

p6rt commented Oct 28, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt closed this as completed Oct 28, 2015
@p6rt
Copy link
Author

p6rt commented Oct 28, 2015

@jnthn - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant