[stringtemplate-interest] how to fix longstanding bug

Terence Parr parrt at cs.usfca.edu
Tue Jul 25 09:20:56 PDT 2006


On Jul 24, 2006, at 6:53 PM, Kunle Odutola wrote:
>
> Fails on C# too (i.e. prints ietrator contents only one).

This is ok I think as you are passing in something that has  
sideeffects, the iterator cursor.  so not our fault.  it is our fault  
when you say rest(names) and ref it twice with bad effect.

>> Suggestions?  I'd really like at least the iterators I create to be
>> "reusable" within same template.
>
> Only sure way is to wrap *all* incoming iterators in a collection  
> of some
> sort. A bit like RestCollection does. Heavy-ish overhead unless, it is
> possible to detect in advance if an iterator is indeed used  
> repeatedly.

no way to detect...i think if i keep a ptr to original datastructure  
it would work by creating new iterator off that each time.  Won't  
solve rest(rest(names)) however as rest would return an  
iterator...hmm..could I make that work?  Each call to next() or  
hasNext() would force a new cached iterator...I'd have to have  
special case code in a few places.   ick.  Apparently this isn't much  
of a problem; I say we punt!

Ter


More information about the stringtemplate-interest mailing list