http://imagej.273.s1.nabble.com/Bug-in-boolean-macro-expression-tp5008047p5008079.html
the simplified precedence scheme for operators in the ImageJ macro language is well documented:
I guess that this simplification helps to keep the macro interpreter simple and also very fast (considering that it uses no kind of compilation or abstract syntax tree).
> Hi Johannes,
>
> I always thought that precedences like "MULTIPLY before ADD" in algebra, or "AND before OR" in boolean algebra (which uses the same notation * and +), have some logical reason that is stronger than the laziness of Unix programmers. But what matters is that it is an established convention.
> I sent this to the List not because I wasn't aware of the work-around beforehand. Instead, I wanted to make aware of an inconsistency when converting code between macro and java(script), which usually works surprisingly well. Secondly, I wanted to ask Wayne to remove something which I considered to be a simple bug.
>
> Norbert
>
>
>
>
> On 6. Jun 2014, at 0:16, Johannes Schindelin <
[hidden email]> wrote:
>
> 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
>
> Norbert Vischer
> Research Engineer
> Centre for Advanced Microscopy
> Swammerdam Institute for Life Sciences (SILS)
> University of Amsterdam
> Science Park 904
> 1098 XH Amsterdam, the Netherlands
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html