Using a function that returns a string in an boolean expression fails

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Using a function that returns a string in an boolean expression fails

Stein Rørvik
There is a regression bug in the macro parser that has appeared quite recently.
A lot of different macro functions returning strings now fail when used inside a boolean expression.

Here are some example combinations and they all fail, except for Color.foreground:

print("\\Clear");
List.set("MyKey", "MyValue");
print(List.get("MyKey")); //ok, prints MyValue
if (List.get("MyKey") != "") print(List.get("MyKey")); //fails

print(Color.foreground); //ok, prints white
if (Color.foreground == "white") print("foreground is white"); //ok

run("Blobs (25K)");
dir = getDirectory("image");
print(dir); //ok, prints C:\Users\steinr\ImageJ\samples\
print(File.getParent(dir)); //ok, prints C:\Users\steinr\ImageJ
if (File.getParent(dir) == "C:\\Users\\steinr\\ImageJ") print("sample image from ImageJ"); //fails

print(File.separator()); //ok, prints \
if (File.separator() == "\\") print("the OS is windows"); //fails
selectWindow("Log");

print(IJ.getToolName()); //ok, prints rectangle
if (IJ.getToolName() == "rectangle") print("rectangle tool is active"); //fails

print(IJ.getFullVersion);
if (IJ.getFullVersion >= "1.53i29") print("string functions cannot be used in boolean expressions"); //fails

It seems these regressions were introduced in 1.53i29 as they are working in 1.53i27 and below.

Stein

-----Original Message-----
Sent: 12. mars 2021 19:47
Subject: Re: Using a function that returns a string in the str.*() functions fails

> On Mar 8, 2021, at 10:35 AM, Stein Rørvik <[hidden email]> wrote:
>
> There seems to be a glitch in the macro parser when trying to use a function that returns a string as input in the str.*() functions:
>
> The following fails:
>
> run("Blobs (25K)");
> if (getTitle().contains("blobs")) showMessage("this is the blobs image");
>
> run("Blobs (25K)");
> if (getTitle().endsWith("gif")) showMessage("this is a GIF image");

This bug is fixed in the 1.53i29 daily build.

> Another thing: It would be useful if it was mentioned in the macro functions documentation what version number these useful str.*() functions were introduced, so that one can insert the appropriate requires() statement before using them in a macro.

I updated the documentation for the str.*() functions, under "String Functions" in the Macro Functions list, so it mentions the version of ImageJ required.

These string functions, where 's' is a string variable, are also available in ImageJ 1.52t and newer: s.charAt(i), s.contains(s2), s.endsWith(s2), s.indexOf(s2), s.lastIndexOf(s2), s.length, s.matches(s2), s.replace(s1,s2), s.startsWith(s2), s.substring(i1,i2), s.substring(i), s.toLowerCase, s.toUpperCase, s.trim.

-wayne

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C3085f426b68246e1df0408d8e58777eb%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637511717298830727%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=aswIyusu70U%2FCwg0Kzb%2FBLjA2XcRqzrMpf5ETrlZ3cY%3D&amp;reserved=0

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Using a function that returns a string in an boolean expression fails

Wayne Rasband-2
> On Mar 22, 2021, at 2:24 PM, Stein Rørvik <[hidden email]> wrote:
>
> There is a regression bug in the macro parser that has appeared quite recently.
> A lot of different macro functions returning strings now fail when used inside a boolean expression.

This regression is fixed in the ImageJ 1.53i42 daily build.

The daily build also has an improved version of the Plugins>Utilities>Benchmark command.  It uses two little known, but very useful, features contributed by Norbert Vischer that allow subordinate status bar messages and progress bars to be suppressed. A plugin version is at

http://wsr.imagej.net/plugins/Benchmark.java

-wayne


> Here are some example combinations and they all fail, except for Color.foreground:
>
> print("\\Clear");
> List.set("MyKey", "MyValue");
> print(List.get("MyKey")); //ok, prints MyValue
> if (List.get("MyKey") != "") print(List.get("MyKey")); //fails
>
> print(Color.foreground); //ok, prints white
> if (Color.foreground == "white") print("foreground is white"); //ok
>
> run("Blobs (25K)");
> dir = getDirectory("image");
> print(dir); //ok, prints C:\Users\steinr\ImageJ\samples\
> print(File.getParent(dir)); //ok, prints C:\Users\steinr\ImageJ
> if (File.getParent(dir) == "C:\\Users\\steinr\\ImageJ") print("sample image from ImageJ"); //fails
>
> print(File.separator()); //ok, prints \
> if (File.separator() == "\\") print("the OS is windows"); //fails
> selectWindow("Log");
>
> print(IJ.getToolName()); //ok, prints rectangle
> if (IJ.getToolName() == "rectangle") print("rectangle tool is active"); //fails
>
> print(IJ.getFullVersion);
> if (IJ.getFullVersion >= "1.53i29") print("string functions cannot be used in boolean expressions"); //fails
>
> It seems these regressions were introduced in 1.53i29 as they are working in 1.53i27 and below.
>
> Stein
>
> -----Original Message-----
> Sent: 12. mars 2021 19:47
> Subject: Re: Using a function that returns a string in the str.*() functions fails
>
>> On Mar 8, 2021, at 10:35 AM, Stein Rørvik <[hidden email]> wrote:
>>
>> There seems to be a glitch in the macro parser when trying to use a function that returns a string as input in the str.*() functions:
>>
>> The following fails:
>>
>> run("Blobs (25K)");
>> if (getTitle().contains("blobs")) showMessage("this is the blobs image");
>>
>> run("Blobs (25K)");
>> if (getTitle().endsWith("gif")) showMessage("this is a GIF image");
>
> This bug is fixed in the 1.53i29 daily build.
>
>> Another thing: It would be useful if it was mentioned in the macro functions documentation what version number these useful str.*() functions were introduced, so that one can insert the appropriate requires() statement before using them in a macro.
>
> I updated the documentation for the str.*() functions, under "String Functions" in the Macro Functions list, so it mentions the version of ImageJ required.
>
> These string functions, where 's' is a string variable, are also available in ImageJ 1.52t and newer: s.charAt(i), s.contains(s2), s.endsWith(s2), s.indexOf(s2), s.lastIndexOf(s2), s.length, s.matches(s2), s.replace(s1,s2), s.startsWith(s2), s.substring(i1,i2), s.substring(i), s.toLowerCase, s.toUpperCase, s.trim.
>
> -wayne

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Using a function that returns a string in an boolean expression fails

Stein Rørvik
Thanks for the quick fix!

Now my examples work.
I tried some more string functions in Boolean expression and they mostly worked except for this one:

run("Blobs (25K)");
Property.setSliceLabel("test 123", 1);
if (Property.getSliceLabel != "") print(Property.getSliceLabel); //fails
if (Property.getSliceLabel() != "") print(Property.getSliceLabel); //fails

The error message is different with or without the ()

This regression is older, it works in 1.53a and fails in 1.53b and after.

Also, the syntax is a bit inconsistent here: setSliceLabel requires the slice number to be specified, while getSliceLabel does not. What about having the slice number optional in both cases, so that the slice number will be used if specified and the current slice will be used if not?

Stein

-----Original Message-----
Sent: 23. mars 2021 03:09
Subject: Re: Using a function that returns a string in an boolean expression fails

> On Mar 22, 2021, at 2:24 PM, Stein Rørvik <[hidden email]> wrote:
>
> There is a regression bug in the macro parser that has appeared quite recently.
> A lot of different macro functions returning strings now fail when used inside a boolean expression.

This regression is fixed in the ImageJ 1.53i42 daily build.

The daily build also has an improved version of the Plugins>Utilities>Benchmark command.  It uses two little known, but very useful, features contributed by Norbert Vischer that allow subordinate status bar messages and progress bars to be suppressed. A plugin version is at

https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwsr.imagej.net%2Fplugins%2FBenchmark.java&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C8c9a2c6bdb37412597eb08d8eda0c83f%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637520622126349183%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=Kah5mS%2BfktjLPavyeve2zy%2FRncchewkYED2i7HFD6p4%3D&amp;reserved=0

-wayne


> Here are some example combinations and they all fail, except for Color.foreground:
>
> print("\\Clear");
> List.set("MyKey", "MyValue");
> print(List.get("MyKey")); //ok, prints MyValue
> if (List.get("MyKey") != "") print(List.get("MyKey")); //fails
>
> print(Color.foreground); //ok, prints white
> if (Color.foreground == "white") print("foreground is white"); //ok
>
> run("Blobs (25K)");
> dir = getDirectory("image");
> print(dir); //ok, prints C:\Users\steinr\ImageJ\samples\
> print(File.getParent(dir)); //ok, prints C:\Users\steinr\ImageJ
> if (File.getParent(dir) == "C:\\Users\\steinr\\ImageJ") print("sample image from ImageJ"); //fails
>
> print(File.separator()); //ok, prints \
> if (File.separator() == "\\") print("the OS is windows"); //fails
> selectWindow("Log");
>
> print(IJ.getToolName()); //ok, prints rectangle
> if (IJ.getToolName() == "rectangle") print("rectangle tool is active"); //fails
>
> print(IJ.getFullVersion);
> if (IJ.getFullVersion >= "1.53i29") print("string functions cannot be used in boolean expressions"); //fails
>
> It seems these regressions were introduced in 1.53i29 as they are working in 1.53i27 and below.
>
> Stein
>
> -----Original Message-----
> Sent: 12. mars 2021 19:47
> Subject: Re: Using a function that returns a string in the str.*() functions fails
>
>> On Mar 8, 2021, at 10:35 AM, Stein Rørvik <[hidden email]> wrote:
>>
>> There seems to be a glitch in the macro parser when trying to use a function that returns a string as input in the str.*() functions:
>>
>> The following fails:
>>
>> run("Blobs (25K)");
>> if (getTitle().contains("blobs")) showMessage("this is the blobs image");
>>
>> run("Blobs (25K)");
>> if (getTitle().endsWith("gif")) showMessage("this is a GIF image");
>
> This bug is fixed in the 1.53i29 daily build.
>
>> Another thing: It would be useful if it was mentioned in the macro functions documentation what version number these useful str.*() functions were introduced, so that one can insert the appropriate requires() statement before using them in a macro.
>
> I updated the documentation for the str.*() functions, under "String Functions" in the Macro Functions list, so it mentions the version of ImageJ required.
>
> These string functions, where 's' is a string variable, are also available in ImageJ 1.52t and newer: s.charAt(i), s.contains(s2), s.endsWith(s2), s.indexOf(s2), s.lastIndexOf(s2), s.length, s.matches(s2), s.replace(s1,s2), s.startsWith(s2), s.substring(i1,i2), s.substring(i), s.toLowerCase, s.toUpperCase, s.trim.
>
> -wayne

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C8c9a2c6bdb37412597eb08d8eda0c83f%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637520622126349183%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=nMc5PHLzRV%2B4RqzOBagdS3RpxAHYGfCHNQOJr7wnfBo%3D&amp;reserved=0

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Using a function that returns a string in an boolean expression fails

Gabriel Landini
In reply to this post by Stein Rørvik
> The daily build also has an improved version of the
> Plugins>Utilities>Benchmark command.  It uses two little known, but very
> useful, features contributed by Norbert Vischer that allow subordinate
> status bar messages and progress bars to be suppressed.

Hi, I was a bit confused  by this. It seems that the Benchmark command now  
use a 5kx5k image instead of the image one has open?

Perhaps this old benchmark macro should be removed as it does not do what it
did before:
https://imagejdocu.list.lu/faq/technical/
are_there_performance_statistics_to_compare_against_my_system

Cheers

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Using a function that returns a string in an boolean expression fails

Wayne Rasband-2
Hi Gabrial,

Your benchmark macro at

    https://imagejdocu.list.lu/faq/technical/are_there_performance_statistics_to_compare_against_my_system

is working again with the 1.53i43 daily build. The Plugins>Utilities>Benchmark command runs the previous version when the current image is 512x512 and RGB. Here is the output from running the macro on an M1 (ARM64) MacBook Air with 8GB of RAM:

  ImageJ: 1.53i
  OS : Mac OS X 11.2
  Java: 13.0.6, vm: 13.0.6+5-MTS Azul Systems, Inc.
  Benchmark best: 0.119
  Benchmark worst: 0.129

-wayne


> On Mar 23, 2021, at 7:26 AM, Gabriel Landini <[hidden email]> wrote:
>
>> The daily build also has an improved version of the
>> Plugins>Utilities>Benchmark command.  It uses two little known, but very
>> useful, features contributed by Norbert Vischer that allow subordinate
>> status bar messages and progress bars to be suppressed.
>
> Hi, I was a bit confused  by this. It seems that the Benchmark command now  
> use a 5kx5k image instead of the image one has open?
>
> Perhaps this old benchmark macro should be removed as it does not do what it
> did before:
> https://imagejdocu.list.lu/faq/technical/
> are_there_performance_statistics_to_compare_against_my_system
>
> Cheers
>
> Gabriel
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Using a function that returns a string in an boolean expression fails

Wayne Rasband-2
In reply to this post by Stein Rørvik
> On Mar 23, 2021, at 4:47 AM, Stein Rørvik <[hidden email]> wrote:
>
> Thanks for the quick fix!
>
> Now my examples work.
> I tried some more string functions in Boolean expression and they mostly worked except for this one:
>
> run("Blobs (25K)");
> Property.setSliceLabel("test 123", 1);
> if (Property.getSliceLabel != "") print(Property.getSliceLabel); //fails
> if (Property.getSliceLabel() != "") print(Property.getSliceLabel); //fails

This regression is fixed in the 1.53i43 daily build.

> The error message is different with or without the ()
>
> This regression is older, it works in 1.53a and fails in 1.53b and after.
>
> Also, the syntax is a bit inconsistent here: setSliceLabel requires the slice number to be specified, while getSliceLabel does not. What about having the slice number optional in both cases, so that the slice number will be used if specified and the current slice will be used if not?

Property.getSliceLabel, Property.getSliceLabel() and Property.getSliceLabel(slice) all work with the daily build.

-wayne


> Stein
>
> -----Original Message-----
> Sent: 23. mars 2021 03:09
> Subject: Re: Using a function that returns a string in an boolean expression fails
>
>> On Mar 22, 2021, at 2:24 PM, Stein Rørvik <[hidden email]> wrote:
>>
>> There is a regression bug in the macro parser that has appeared quite recently.
>> A lot of different macro functions returning strings now fail when used inside a boolean expression.
>
> This regression is fixed in the ImageJ 1.53i42 daily build.
>
> The daily build also has an improved version of the Plugins>Utilities>Benchmark command.  It uses two little known, but very useful, features contributed by Norbert Vischer that allow subordinate status bar messages and progress bars to be suppressed. A plugin version is at
>
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwsr.imagej.net%2Fplugins%2FBenchmark.java&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C8c9a2c6bdb37412597eb08d8eda0c83f%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C0%7C637520622126349183%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=Kah5mS%2BfktjLPavyeve2zy%2FRncchewkYED2i7HFD6p4%3D&amp;reserved=0
>
> -wayne
>
>
>> Here are some example combinations and they all fail, except for Color.foreground:
>>
>> print("\\Clear");
>> List.set("MyKey", "MyValue");
>> print(List.get("MyKey")); //ok, prints MyValue
>> if (List.get("MyKey") != "") print(List.get("MyKey")); //fails
>>
>> print(Color.foreground); //ok, prints white
>> if (Color.foreground == "white") print("foreground is white"); //ok
>>
>> run("Blobs (25K)");
>> dir = getDirectory("image");
>> print(dir); //ok, prints C:\Users\steinr\ImageJ\samples\
>> print(File.getParent(dir)); //ok, prints C:\Users\steinr\ImageJ
>> if (File.getParent(dir) == "C:\\Users\\steinr\\ImageJ") print("sample image from ImageJ"); //fails
>>
>> print(File.separator()); //ok, prints \
>> if (File.separator() == "\\") print("the OS is windows"); //fails
>> selectWindow("Log");
>>
>> print(IJ.getToolName()); //ok, prints rectangle
>> if (IJ.getToolName() == "rectangle") print("rectangle tool is active"); //fails
>>
>> print(IJ.getFullVersion);
>> if (IJ.getFullVersion >= "1.53i29") print("string functions cannot be used in boolean expressions"); //fails
>>
>> It seems these regressions were introduced in 1.53i29 as they are working in 1.53i27 and below.
>>
>> Stein
>>
>> -----Original Message-----
>> Sent: 12. mars 2021 19:47
>> Subject: Re: Using a function that returns a string in the str.*() functions fails
>>
>>> On Mar 8, 2021, at 10:35 AM, Stein Rørvik <[hidden email]> wrote:
>>>
>>> There seems to be a glitch in the macro parser when trying to use a function that returns a string as input in the str.*() functions:
>>>
>>> The following fails:
>>>
>>> run("Blobs (25K)");
>>> if (getTitle().contains("blobs")) showMessage("this is the blobs image");
>>>
>>> run("Blobs (25K)");
>>> if (getTitle().endsWith("gif")) showMessage("this is a GIF image");
>>
>> This bug is fixed in the 1.53i29 daily build.
>>
>>> Another thing: It would be useful if it was mentioned in the macro functions documentation what version number these useful str.*() functions were introduced, so that one can insert the appropriate requires() statement before using them in a macro.
>>
>> I updated the documentation for the str.*() functions, under "String Functions" in the Macro Functions list, so it mentions the version of ImageJ required.
>>
>> These string functions, where 's' is a string variable, are also available in ImageJ 1.52t and newer: s.charAt(i), s.contains(s2), s.endsWith(s2), s.indexOf(s2), s.lastIndexOf(s2), s.length, s.matches(s2), s.replace(s1,s2), s.startsWith(s2), s.substring(i1,i2), s.substring(i), s.toLowerCase, s.toUpperCase, s.trim.
>>
>> -wayne

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html