Main siteMain site  ForumForum  ForumSearch  Private messageEmail contact  RegisterRegister  Log inLog in 
Topic: Expression evaluator with multiple outputs
Reply to topic
Author Message
snovotill



Joined: Feb 8, 2013
Posts: 80

PostPosted: Oct 27, 2013 10:27 PM    Post subject: Expression evaluator with multiple outputs

Hi Jarek/all, here's a good ExpressionEvaluator problem for the forum:

I'm able to use nested Ternary operators, as well as multiple outputs, but something goes wrong when I try to use both together.

The following expression fails to compile. I've run into this situation several times so I'm reaching out for a fix:

In1==-1 ? Out1=0;Out2=0 : In1==0 ? Out1=1;Out2=0 : Out1=1;Out2=1

Thanks kindly,
...Stepan
jarek



Joined: Oct 22, 2007
Posts: 1073

PostPosted: Oct 27, 2013 11:03 PM    Post subject:

You can't use the tenary operator across multiple outputs.

If you wish to use multiple outputs, then each output starts with OutX= and ends with a semicolon. That is main level.
snovotill



Joined: Feb 8, 2013
Posts: 80

PostPosted: Oct 29, 2013 2:51 AM    Post subject:

Okay. I was just about to implement a Programmable Logic Array inside ExpressionEvaluator. And so the simple work around will be to use a separate ExpressionEvaluator for each output. Cheers.
snovotill



Joined: Feb 8, 2013
Posts: 80

PostPosted: Nov 2, 2013 10:03 PM    Post subject:

I'm getting a lot of this, so here's one last kick at the cat Jarek/All:

Consider this typical ExpressionEvaluator scenario for instance:

(In1==0 && In2!=0) ? 1:0

It seems to me that the core expression should evaluate to 0 or 1 directly:

Out1=(In1==0 && In2!=0)

But the skeleton above fails to compile in expressionEvaluator.

I've tried curly brackets, backticks, the \"if\", and various combinations of many different things.
Is there a way to force this to evaluate without the need for Ternary, so I can use multiple outputs?

thanks kindly
jarek



Joined: Oct 22, 2007
Posts: 1073

PostPosted: Nov 2, 2013 11:54 PM    Post subject:

No, the Out1=(In1==0 && In2!=0) will not evaluate directly. Because in java (unlike in C) boolean value (the result of the this expression's right side) is a different type than a number (e.g. float or integer). So it can't be assigned directly, it has to be converted to a number first.

jarek



Joined: Oct 22, 2007
Posts: 1073

PostPosted: Nov 4, 2013 5:52 AM    Post subject:

I am not sure if that can make any difference for what you are doing.

But it is possible to use output variables as input variables in an expression.

For example:

Out1=In1;Out2=Out1*2;Out3=Out2>0?Out1:0

The expression is resolved from left to right. So in the above the first is Out1, then Out2 etc.
snovotill



Joined: Feb 8, 2013
Posts: 80

PostPosted: Nov 5, 2013 11:34 PM    Post subject:

Very cool! I'm glad you posted that Jarek, thanks.
Reply to topic