[stringtemplate-interest] [ST4 Beta4] Default args are not always evaluated in the context of their template

Terence Parr parrt at cs.usfca.edu
Thu Feb 17 13:33:29 PST 2011


On Feb 17, 2011, at 1:22 PM, Udo Borkowski wrote:

> Hi Ter,
> 
>> Hi Udo. I'm pretty sure Sam is correct. This is a lazy evaluation issue.  comment inline ####
> 
> Yes, Sam is correct, in describing how the system behaves and why. I never doubted this.
> 
> My question is: is this the *expected* behavior, i.e. is this the behavior you had in mind when saying "the default args are formally defined to have the same context as the template itself, hence, default arguments can see the other arguments."? Or is it just the way things are currently implemented?

That is the intention and how it works.  You are passing p2 to another context so that statement about default args has nothing to do with it.

> 
> Regarding your question:
>>> t2(p1,p2) ::= <<
>>> inside t2: p1=<p1>, p2=<p2>    #### <p2> evaluates {<p1>} and p1 has value "B", right?
> 
> p1 has the value "A" in the context of t1. p1 has the value "B" in the context of t2. If I understood you correctly the subtemplate {<p1>} has the same context as the template t1, hence p1 in the subtemplate {<p1>} has value "A" (not "B").

That is where the default arg with eval.  If you pass to ANOTHER context, it will eval differently (in that context).
Ter


More information about the stringtemplate-interest mailing list