[Aldor-l] empty Generator?
Ralf Hemmecke
ralf at hemmecke.de
Thu Feb 15 07:57:38 EST 2007
> 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