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

feature request: lazy evaluated list: keyword lazy #5154

Closed
p6rt opened this issue Feb 22, 2016 · 4 comments
Closed

feature request: lazy evaluated list: keyword lazy #5154

p6rt opened this issue Feb 22, 2016 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Feb 22, 2016

Migrated from rt.perl.org#127601 (status was 'rejected')

Searchable as RT127601$

@p6rt
Copy link
Author

p6rt commented Feb 22, 2016

From Greg.London@infineon.com

Current format for a lazily evaluated list​:

  my $lazylist = (0, { $_ + 3 } ...^ * > 10);

^*> is incoherent line noise.

Please consider making a builtin function that looks kind of like a "for loop" but is lazily evaluated.

my $lazylist = lazy ($_=0; $_ <= 10; $_+=3);

The syntax for a FOR() loop is well established and already has everything needed to define a lazy list.
(start condition; end condition; increment condition)

Keep the line noise version if you want, but a lazy() function would be much more natural and intuitive for oddball situations and would need almost zero explanation.

@p6rt
Copy link
Author

p6rt commented Feb 24, 2016

From @coke

On Mon Feb 22 14​:43​:21 2016, Greg.London@​infineon.com wrote​:

Current format for a lazily evaluated list​:

my $lazylist = (0, { $_ + 3 } ...^ * > 10);

^*> is incoherent line noise.

Thanks for trying out Perl 6.

In case this wasn't just a rant, the ^ here is tied to the sequence, and means
exclude the endpoint. For example, 1...^4 produces a three element sequence.

The * is a Whatever star, and is ubiquitous in Perl 6. It's a way to generate
a closure; * > 10 here means "something greater than 10". So altogether,
...^ * > 10 should read, a sequence up to , but not including, a value greater than 10.

So, as it turns out, this isn't really a list that needs lazifying, it's only got
4 elements​: 0, 3, 6, 9. The 12 is greater than 10, so we take everything up to but
not including it.

Please consider making a builtin function that looks kind of like a
"for loop" but is lazily evaluated.

my $lazylist = lazy ($_=0; $_ <= 10; $_+=3);

The syntax for a FOR() loop is well established and already has
everything needed to define a lazy list.
(start condition; end condition; increment condition)

In Perl 6, the C-style for loop you reference is spelled "loop".

loop (my $i = 0; $i < 10; $i++) { say $i } # prints out 0 to 9.

Keep the line noise version if you want, but a lazy() function would
be much more natural and intuitive for oddball situations and would
need almost zero explanation.

Turns out we already have a "lazy". So this code works today.

my $lazylist = lazy loop (my $i=0; ; $i++) { $i };
say $lazylist[1000];

Rejecting ticket. I encourage you to checkout docs.perl6.org
and/or stop by on the irc channel if you have more questions.

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Feb 24, 2016

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

@p6rt
Copy link
Author

p6rt commented Feb 24, 2016

@coke - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Feb 24, 2016
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