Browse files

coroutines

  • Loading branch information...
1 parent a784c68 commit 64de59865997a12f3b1fe75fb8675b0ca672eff0 @moritz moritz committed Nov 4, 2011
Showing with 20 additions and 4 deletions.
  1. +19 −0 answers.md
  2. +1 −4 questions
View
19 answers.md
@@ -76,3 +76,22 @@ on an expression, and item context (not flattening) with `$( ... )`
or by calling the `.item` method on an expression.
`[...]` array literals do not flatten into lists.
+
+
+## Does Perl 6 have coroutines? What about `yield`?
+
+Perl 6 has no `yield` statement like python does, but it does offer similar
+functionality through lazy lists. There are two popular ways to write
+routines that return lazy lists:
+
+ # first method, gather/take
+ my @values := gather while have_data() {
+ # do some computations
+ take some_data();
+ # do ore computations
+ }
+
+ # second method, use .map or similar method
+ # on a lazy list
+ my @squares := (1..*).map(-> $x { $x * $x });
+
View
5 questions
@@ -1,10 +1,6 @@
Language features/builtins
-* what's the point of the @ and % sigils when you don't need to explicitly
- dereference array refs? if my $x = (0, 1); say $x[0] works, why use @x
- instead?
* are Perl 6 threads better than Perl 5 threads?
-* does Perl 6 have coroutines?
Meta:
@@ -18,3 +14,4 @@ ANSWERED:
* if Str is immutable, how does s/// work? if Int is immutable, how does $i++
work?
* array references and list/item context
+* does Perl 6 have coroutines?

0 comments on commit 64de598

Please sign in to comment.