Commit Graph

23 Commits

Author SHA1 Message Date
Eli Barzilay
2368290cdb Test now that the generator is not in a running state when it's called.
The previous problem was just a bug.

svn: r17984
2010-02-05 03:22:15 +00:00
Eli Barzilay
d5822a3ee5 Remove the special case hack for getting zero values at the end of a
generator.  This will make this:

  (generator (yield 1) (yield))

also repeat #<void> when it's done which will be very confusing.  Better
just add a note in the docs on (generator (yield 1)) returning no values
when it's done.

Also, remove some of the `case-lambda' optimizations...

svn: r17983
2010-02-05 03:22:12 +00:00
Eli Barzilay
3a08648dab Added a `running' state, which is visible only from inside the
generator.  (Also considered making it an error when the generator is
called while it is running, but that doesn't allow (yield (yield X))
fun.)

svn: r17982
2010-02-05 03:22:09 +00:00
Eli Barzilay
2f62cb192e Allow using `yield' with any number of arguments which will be returned
as multiple values.  (These `case-lambda's are for making it fast, which
is probably stupid given how slow this is anyway.)

svn: r17981
2010-02-05 03:22:07 +00:00
Eli Barzilay
f1dcf49d38 Added `generator-state', implemented using a local state (which also
simplifies the code that raises an error from the last change).

svn: r17980
2010-02-05 03:22:04 +00:00
Eli Barzilay
505034ea26 The generator function can now be used to send values to the generator.
For example,

  (define g (generator (yield (yield (yield 1)))))
  (list (g) (g 2) (g 3) (g 4) (g) (g))

evaluates to '(1 2 3 4 4 4).  This is something that Python does (as a
generator.send method), which might be useful for using generators as
co-routines, and it is actually easy to implement since sending values
is exactly what we get when the generator call is actually calling the
saved continuation.  So most of the change is dealing with the
technicalities of throwing an error when the generator is called with
some arguments, when that's done after it's terminated (at the stage
where it's repeating the last value for ever).

A few tests added for this.

svn: r17979
2010-02-05 03:22:01 +00:00
Eli Barzilay
18c8e41fac Make it possible for the last expression in the body of a generator to
return any number of values.  They will be collected and used as the
repeat-forever result of calling the generator again.

Note: there's an exception for using no values -- instead of returning
no values forever, use void, since no values can be more surprising, and
it can happen when someone uses something like

  (generator (yield 1) (yield 2) (yield 3))

since the result of `yield' is (values).  (This will change in a
following commit, but even then it will be popular since people will
usually invoke the generator with no arguments which leads to the zero
values.  Could be solved if you use (g (void)) -- but that's awkward, I
think.)

svn: r17978
2010-02-05 03:21:59 +00:00
Eli Barzilay
6b7c199326 * Some reorganization of code
* Rename `make-repeated-sequence-generator' -> `sequence->repeated-generator'
* Several tests for `sequence->generator'

svn: r17586
2010-01-09 04:45:39 +00:00
Jon Rafkind
a0ba9a7649 add sequence->generator and change make-repeated-sequence-generator to use that instead of infinite-generator
svn: r17583
2010-01-08 22:02:42 +00:00
Jon Rafkind
db44bb9e7a add infinite-generator and make-repeated-sequence-generator
svn: r17559
2010-01-07 23:23:56 +00:00
Jon Rafkind
db6a9de7ed add 'infinite' generator
svn: r17552
2010-01-07 21:53:37 +00:00
Eli Barzilay
80a386e482 minor fixes
svn: r16012
2009-09-14 21:21:28 +00:00
Jon Rafkind
6137510396 make generators use a parameterized yield function
svn: r16010
2009-09-14 21:11:07 +00:00
Eli Barzilay
9ecbffa70e svn: r15818 2009-08-27 20:34:18 +00:00
Jon Rafkind
e4f86edbed a few name changes
svn: r15816
2009-08-27 16:42:12 +00:00
Eli Barzilay
78471a5b86 better name-age
svn: r15815
2009-08-27 16:08:27 +00:00
Eli Barzilay
572f7f849b suggested revision
svn: r15812
2009-08-27 12:16:26 +00:00
Jon Rafkind
f63a9046af comment about define-sequence-syntax
svn: r15810
2009-08-26 22:05:13 +00:00
Jon Rafkind
4697b7fd6f use gensym and dont keep track of position
svn: r15808
2009-08-26 21:43:42 +00:00
Jon Rafkind
56c4fe6c7d cosmetic fixes. add in-generator
svn: r15807
2009-08-26 21:29:02 +00:00
Eli Barzilay
98f9472dd4 reformat
svn: r15806
2009-08-26 21:07:42 +00:00
Eli Barzilay
ab7caff9bc reformat
svn: r15805
2009-08-26 21:05:04 +00:00
Jon Rafkind
f61f933b8b add library for creating generator sequences
svn: r15803
2009-08-26 20:54:22 +00:00