[stringtemplate-interest] how to fix longstanding bug
Kunle Odutola
Kunle_Odutola at hotmail.com
Mon Jul 24 18:53:44 PDT 2006
Ter,
> Ok, so a bug exists with the rest(attribute) operator. If you pass
> the result as a parameter it gets mess up if you ref that parameter
> >1 time. Here is the unit test that fails:
>
> /** BUG! Fix this. Iterator is not reset from first to second $x$
> * Either reset the iterator or pass an attribute that knows to get
> * the iterator each time. Seems like first, tail do not
> * have same problem as they yield objects.
> *
> * Maybe make a RestIterator like I have CatIterator.
> */
> public void testRepeatedRestOpAsArg() throws Exception {
ST# has a RestCollection that handles this so, this unit tests passes in
ST#.
> It yields "Tom, " not "Tom, Tom". I said, "oh, just reset iterator
> when you hit the end". There *is* no reset method! i cannot reset
> any incoming attributes as the following unit test shows:
C# IEnumerators can be reset. They aren't at the moment though.
> /** If an iterator is sent into ST, it must be cannot be reset after
> each
> * use so repeated refs yield empty values. This would
> * work if we passed in a List not an iterator. Avoid sending in
> iterators
> * if you ref it twice.
> */
> public void testRepeatedIteratedAttrFromArg() throws Exception {
Fails on C# too (i.e. prints ietrator contents only one).
> 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.
C# also has the option of simply Reset()-ing iterators but that breaks with
"positioned iterators" (i.e. iterators deliberately positioned at a specific
point in the underlying collection).
Kunle
More information about the stringtemplate-interest
mailing list