Posted by
dscho on
Jun 05, 2014; 10:16pm
URL: http://imagej.273.s1.nabble.com/Bug-in-boolean-macro-expression-tp5008047p5008051.html
Hi Norbert,
On Thu, 5 Jun 2014, Norbert Vischer wrote:
> I get different boolean output for this expression:
>
> a = false && false || true && true;
> print(a);
>
>
> output JavaScript: true
> output Macro: 0
>
>
> Documentation says:
> The ImageJ macro language supports almost all of the standard Java
> operators but with fewer precendence levels.
> But hopefully the above is not intended!
You are asking an awful lot of a toy interpreter. Basically you are asking
to implement the macro language to implement the same priorities with
regards to Boolean operators as Javascript. To repeat: that is an awful
lot.
It is true that Javascript lets && bind stronger than ||. There is no
logical reason to do so, just the tradition of the Unix shell where people
wanted to be able to write
do_this && do_that && do_yet_another_thing || fail
where fail would be executed whenever anything in that && chain before
that failed.
But from a mathematical point of view, it makes no sense at all to give &&
preference over || whatsoever, these operators are equivalent (a && b is
exactly the same as !(!a || !b)).
Therefore, again, you are asking an awful lot of the poor little macro
language. Is it really that hard to add explicit parentheses? Or to switch
to a real language for that massive program of yours?
Ciao,
Johannes
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html