23.2 Generator

To make generators available in Axiom we can fortunately extend this type, and exactly those operations with which we extend Generator will be visible in Axiom.

617ext: Generator 617  (613)
extend Generator(S:Type): with {
        OutputType;
        partialNext!: % -> Partial S;
        next!: % -> S;
} == add {
        (tw: TextWriter) << (x: %): TextWriter == {
                import from String;
                tw << "[<generator>]";
        }

        next!(g:%): S == {
                for x in (g pretend Generator S) repeat return x;
                throw GeneratorException;
        }

        partialNext!(g: %): Partial S == {
                for x in (g pretend Generator S) repeat return [x];
                failed;
        }
}

Defines:
Generator, used in chunks 64–67, 78–80, 86a, 87b, 91–93, 100, 101, 103a, 104a, 110–13, 120, 124, 125a, 128, 131–33, 141–43, 153, 155a, 157–59, 163a, 169b, 170, 178, 179, 185a, 186, 188a, 189, 192, 204, 205, 207, 213, 219, 230, 232a, 257–59, 262, 263a, 267–69, 271–75, 278b, 280a, 281b, 285a, 314, 318b, 321, 341b, 345a, 346a, 350, 352, 357, 358, 361, 363, 364, 389a, 392b, 394, 395, 407, 410, 411, 414c, 419, 420, 425, 426, 447, 476, 491d, 515, 520a, 521a, 572, 579–81, 584, 590, 605, 625, 657, 661a, 665, 678b, 679a, 681b, 699–701, 711–16, 721, 725, 746b, and 761b.

Uses GeneratorException 619b, OutputType 570, Partial 614, and String 65.