[stringtemplate-interest] "Or" and "And" operators in conditionnal always evaluate both operands ?

Damien Urruty lepilache at hotmail.com
Thu Sep 15 06:54:01 PDT 2011


Hi,
The problem I am facing is that my conditional is something like : 
<if(a && a.b)>
Which raises an error in the case a is null (a.b is still evaluated). 
By the way, the error is not very explicit : "templateName : no such property or can't access: null attribute". I spent some time finding where the error came from.
It is not a question of performance, I was just wondering if this behaviour was normal, I mean if this is by design, or if it was a bug.
In my case, I can easily break the if in two separate ifs, so it doesn't really matter. But as in Java the && does not evaluate all the operands if not necessary (the & operator do evaluate each operand), i wanted to know if this behaviour was wanted or not.
Maybe this should be discussed, I know it is not very important, or at least it should be mentionned somewhere in the doc ?
Thanks for your response Sam, have a nice day

From: sharwell at pixelminegames.com
To: lepilache at hotmail.com; stringtemplate-interest at antlr.org
Subject: RE: [stringtemplate-interest] "Or" and "And" operators in conditionnal always evaluate both operands ?
Date: Thu, 15 Sep 2011 08:43:29 -0500



Hi Damien, Since the attributes referenced from a StringTemplate should always be pure (no side effects), then there is no semantic difference between evaluating or not evaluating the second argument. Are you facing a significant performance problem due to the second evaluation? Sam From: stringtemplate-interest-bounces at antlr.org [mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Damien Urruty
Sent: Thursday, September 15, 2011 8:01 AM
To: stringtemplate-interest at antlr.org
Subject: [stringtemplate-interest] "Or" and "And" operators in conditionnal always evaluate both operands ? Hello, I can see that if we use && and || operands in conditionnals, both operands are always evaluated, even if not necessary. For exemple, I have  :  <if(a && b)>...<endif> In my case, a is null, so it is not necessary to evaluate the second argument, right ? Shouldn't the evaluation stop when such a case is encountered ? It is the same for <if(a || b)> with a not null. Maybe I miss something, thanks for your help. 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110915/26f1ef9c/attachment-0001.html 


More information about the stringtemplate-interest mailing list