[Aldor-l] empty Generator?

W Naylor wn at cs.bath.ac.uk
Thu Feb 15 08:27:16 EST 2007


So I guess the problem is that when one tries to look at the Generator, to 
see if it's got anything in it this has to be a desctructive look. Looking 
at the source I see:

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

The only way I can imagine a work around would be do the partialNext! as 
below, then rebuild the original generator (perhaps using the Generator:
        concat: List(%) -> %
function)

a bit dirty I know! but might be some help?

cheers,

Bill

On Thu, 15 Feb 2007, Ralf Hemmecke wrote:

> > However for your grnerator one, the algebra library exports a
> > partialNext!
> > function which allows to detect if g is empty:
> 
> Thank you for your quick answer, but I should have mentioned that I know about
> "next!" and "partialNext!".
> 
> But it does not help to make the following work. If I implement
> 
> empty?(g: Generator(Integer)): Boolean == failed? partialNext! g;
> 
> then
> 
> > > g: Generator Integer := generate yield 123;
> > > b: Boolean empty? g;
> > > l: List Integer := [g];
> 
> would give l=[] instead of l=[123].
> 
> So either there is a way supported by the compiler or it simply is not
> possible.
> 
> Of course I could define MyGenerator which is like a one-token-look-ahead
> stream, but then MyGenerator is different from Generator and it cannot be used
> in library functions that require Generator.
> 
> So my question was in fact, whether Generator is implemented as a
> one-token-look-ahead stream similar to TextReader. (Note that TextReader has a
> function "push!: (Charcater, %) -> ()" to push back one character.)
> 
> Ralf
> 
> 
> 
> 



More information about the Aldor-l mailing list