[stringtemplate-interest] dealing with empty list values

Terence Parr parrt at cs.usfca.edu
Sun Feb 7 12:01:22 PST 2010


Hi Joshua, I wrestled with this concept for quite a while about null values in a list. First, let me remind you that a missing parameter $foo$ is not the empty string--it's actually missing. to be consistent, I decided that null values in a list are missing not empty or blank.

So, my solution to that posting you mentioned is to allow the null option.

Ter
On Feb 6, 2010, at 2:52 AM, Joshua Royalty wrote:

> Hi, I ran into a bit of a stumbling block with a list containing null values.  It seems that ST automatically skips over null values when iterating over a list.
> 
> I searched the archives and found this thread
> http://markmail.org/search/?q=list%3Astringtemplate+dealing+with+empty+list+values#query:list%3Astringtemplate%20dealing%20with%20empty%20list%20values+page:1+mid:fvkxdehqyuyu4jxp+state:results
> 
> Was a solution ever implemented?
> 
> Personally I would find it most intuitive to have the default be to not skip nulls.  Such that "$values:{ v | $if(v)$$v$$else$-1$endif$" would be identical to "$values; separator=\", \", null=\"-1\"$"
> 
> Instead, if you sent values to {test1, null, test2} you get
> test1, test2
> test1, -1, test2
> 
> "$values:{ v | $if(v)$$v$$else$-1$endif$}; separator=\", \", null=\"-1\"$" also prints 'test1, -1, test2'
> 
> Its not logically consistent to skip nulls when iterating over a list and treat them as "" (Empty String) everywhere else.  (A case could also be made that it is not logically consistent to treat them as false in the if statement as well)
> 
> If someone wants to clean nulls out of the list they can use the strip() function, though strictly speaking that should have been handled by the model.
> 
> 
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest



More information about the stringtemplate-interest mailing list