[stringtemplate-interest] H2 test a value

Terence Parr parrt at cs.usfca.edu
Tue Nov 22 11:37:21 PST 2005


On Nov 21, 2005, at 1:27 PM, Jesper Goertz wrote:

> Hi Terence,
>
> StringTemplate is a fine tool, thank you!

Thanks!  How did you find it?

> In the documentation (of List construction) you write that
> "This ability to rearrange attributes is consistent with model-view  
> separation
> because the template cannot alter the data structure nor test its  
> values"
>
> However, it seems to be possible to test for specific values by  
> means of
> a map attribute with boolean values, e.g., with
>
> map.put("b", Boolean.TRUE);

Well, yes, booleans are the only exception but in a sense they are ok  
as you are merely testing the result of a computation in the model.

> you can test for the value "b" like in
>
> t(m,n) ::= "$if (!m.(n))$ $n$ $endif$"

Doesn't this simply yield a property name, which is stored in  
attribute n, such as "salary" of object m?  So if you say m is a map  
with "salary":"99000" and n="salary", it will show text "salary" when  
m.get("salary") is non null.  You are deciding whether to display not  
testing its value to see if it's 42 or whatever.

> When the rest bug has been squashed this can be used to filter out
> values from a list and solve "the last empty value problem" in
> testEmptyIteratedConditionalValueGetsNoSeparator.

Ah, well you can always filter for empty values.  My rule is "you can  
test presence/absence or size or anything else that does not test the  
value of an attribute"

> Is this kosher or a vile hack?

Seems kosher...filtering for nonempty values is trivial:

$names:{n | $if(n)$ $n$ $endif$}$

Ter


More information about the stringtemplate-interest mailing list