[stringtemplate-interest] Question on math operations (plus, minus, etc)

Jiwon Seo jiwon at stanford.edu
Fri Dec 2 16:46:53 PST 2011


Hi,

I need to do some simple subtraction inside a template, like
following. (the reason for this is, it is much simpler to do this in a
template than in Java and pass an argument to the template).

<args:{a | argument_<i> and nesting_<length(params)-i>}>

So, basically I want to be able to compute a number by subtracting an
index from the length of another attributes ( <length(params) - i> )

Is there any way I can do something like this?

The length of the params (in the above example) is limited (like from
1 to 5), so if I can use a map which takes a tuple, I can do
following:

IndexMap ::= [
    (5, 1) : 4,
    (5, 2) : 3,
    (5, 3) : 2,
   ...
    (3, 1): 2,
   ...
    (2, 1): 1,
    default: "ERROR!!!"
]

and use it like this:

<args:{a | argument_<i> and nesting_<IndexMap.(params,i)>}>

But it seems like it is not supported either.

Thanks,

-Jiwon


More information about the stringtemplate-interest mailing list