Issue with string and number value parsing in IJ macro

Something must have changed recently in how ImageJ parses expressions consisting of both string (text) and number values, as noted recently by a user of IJ_Rhizo on Twitter:

The following macro snippet reproduces the issue:

calVal = 42;
counts = newArray(1,2,3);
j=2;
ImRes=12.7;

print(calVal+"     "+counts[j]  * (25.4/ImRes) );

Error:
β€˜)’ expected in line 6: print ( calVal + " " + counts [ j ] <*> ( 25.4 / ImRes ) ) ;

@Wayne did something change recently in the way how ImageJ1 parses these expressions?


Workaround: the issue can be mitigated by adding two parentheses to the print statement above (and to line 545 of the IJ_Rhizo macro):

print(calVal+"     "+(counts[j]  * (25.4/ImRes)) );
2 Likes

Just curious. Did that kind of expression use to work? I don’t remember the reason but very early on when I started using ImageJ, I got used to using the parenthesis to enclose calculations. Then again, if I recall correctly, at the time, you also had to start the expression with a string or else it would think you are trying to add numbers and then throw an error when it found a string instead.

The latest ImageJ daily build (1.52m20) fixes a 1.52i regression that cause macro expressions like "s"+a[i]*n to generate an error. The issue can be reproduced with two lines of macro code:

 a = newArray(1,2);
 print(""+a[0]*2);

The code changes are at: