cglur@onwe.co.za wrote:
> > ;discin('myfile.txt') -> char_rep
> >
> > incharitem(char_rep) -> item_rep;
> >
> > Then char_rep is a procedure which, each time it is called returns the
> > next character from the file myfile.txt ....
> My manual/single-step call to discin apparently re-initialises.
> ie. repeated reading of the *first* byte.
> Apparently the 'counters' of repeaters are not global/persistent.
Every time you call discin, you create a *new* repeater. The counter
for each repeater is persistent. So if you do
discin('myfile.txt') -> char_rep1;
discin('myfile.txt') -> char_rep2;
You get two independent character repeaters, each with its own memory,
that can be at the same or different points in the file at any given
moment, depending on how many times each has been called.
Of course if you do
discin('myfile.txt') -> char_rep;
<other stuff>
discin('myfile.txt') -> char_rep;
Then the second assignment to char_rep replaces the first character
repeater with a new one. The original character repeater no longer has
the name char_rep. Unless you somehow gave it another name before the
second call to discin (e.g., char_rep -> old_char_rep;) then it will
have no name at all, and you will have no way of running it, and it will
eventually get picked up by the garbage collector.
Hope that helps.
Stephen Isard
|