Dear all (probably Wayne),
I have found an issue in the newArray function within what can be a very simple macro. Indeed, the following code is working: a = newArray(5, 5+2); Array.print(a); As the following code: a = newArray(5+1, 5+2); Array.print(a); Is throwing the error that it is expecting an ")" instead of the ",". Which means that is there is something else than "," after the first element it interprets the code as being a newArray(size). I guess the fix for this issue would be to replace the line if (next==STRING_CONSTANT || nextNext==',' || nextNext=='[' || next=='-' || next==PI) return initNewArray(); With if (next==STRING_CONSTANT || nextNext==',' || next==PI || nextNext=='[' || next=='+' || next=='-' || next=='*' || next=='/') return initNewArray(); Within the "Variable[] newArray" method in the " ij.macro. Functions.java" file. My best regards, Philippe Philippe CARL Laboratoire de Bioimagerie et Pathologies UMR 7021 CNRS - Université de Strasbourg Faculté de Pharmacie 74 route du Rhin 67401 ILLKIRCH Tel : +33(0)3 68 85 41 84 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Bonjour Philippe!
Did you try: a = newArray( ""+5+1, 5+2 ); Array.print(a); Regards Herbie -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hallo Herbie,
Your suggestion indeed worked! Thanks a lot! My best regards, Philippe -----Message d'origine----- De : ImageJ Interest Group [mailto:[hidden email]] De la part de Herbie Envoyé : mardi 16 janvier 2018 13:51 À : [hidden email] Objet : Re: Issue on newArray macro function Bonjour Philippe! Did you try: a = newArray( ""+5+1, 5+2 ); Array.print(a); Regards Herbie -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
On 16/01/2018 13:51, Herbie wrote:
> Did you try: > > a = newArray( ""+5+1, 5+2 ); > Array.print(a); Hi Herbie, yes, your solution works, but then the first array element is a String, not a number. See the difference here: a = newArray( ""+5+1, 5+2 ); Array.print(a); print(a[0]+1); // 61, String concatenation print(a[1]+1); // 8, arithmetics 5+2+1 print(a[0]-1); // error (cant do the calculation with a String) Michael -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thanks Michael,
for pointing this out. My approach was based on an assumption I *wrongly* made some time ago, namely that arrays are either composed of strings or numerals. Mea culpa Herbie -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by CARL Philippe (LBP)
On Jan 16, 2018, at 7:37 AM, Philippe CARL <[hidden email]> wrote:
> > Dear all (probably Wayne), > > I have found an issue in the newArray function within what can be a very > simple macro. > > Indeed, the following code is working: > > a = newArray(5, 5+2); > > Array.print(a); > > As the following code: > > a = newArray(5+1, 5+2); > > Array.print(a); > > Is throwing the error that it is expecting an ")" instead of the ",”. Hi Philippe, Your proposed fix for this bug is in the latest daily build (1.51u12). -wayne > Which means that is there is something else than "," after the first element > it interprets the code as being a newArray(size). > > I guess the fix for this issue would be to replace the line > > if (next==STRING_CONSTANT || nextNext==',' > > || nextNext=='[' || next=='-' || next==PI) > > return initNewArray(); > > With > > if (next==STRING_CONSTANT || nextNext==',' || next==PI > > || nextNext=='[' || next=='+' || next=='-' || next=='*' || > next=='/') > > return initNewArray(); > > Within the "Variable[] newArray" method in the " ij.macro. Functions.java" > file. > > My best regards, > > Philippe -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Wayne,
On 16.01.2018 21:20, Wayne Rasband wrote: > Your proposed fix for this bug is in the latest daily build (1.51u12). This bug is not limited to expressions with +,-,* or / For example, while the following works: a = newArray(2, acos(0.2), log(2)); these other lines throw exceptions: a = newArray(acos(0.2), log(2), 2); a = newArray(log(2), 2, acos(0.2)); Jan > >> Which means that is there is something else than "," after the first element >> it interprets the code as being a newArray(size). >> >> I guess the fix for this issue would be to replace the line >> >> if (next==STRING_CONSTANT || nextNext==',' >> >> || nextNext=='[' || next=='-' || next==PI) >> >> return initNewArray(); >> >> With >> >> if (next==STRING_CONSTANT || nextNext==',' || next==PI >> >> || nextNext=='[' || next=='+' || next=='-' || next=='*' || >> next=='/') >> >> return initNewArray(); >> >> Within the "Variable[] newArray" method in the " ij.macro. Functions.java" >> file. >> >> My best regards, >> >> Philippe > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Dear all,
Since my previous posting seems to have launched a discussion, I would have another modification to submit. Indeed, the Array.fill(array, value) macro code up to today only works for numeric values. Thus why not simply replace the following lines: double v = getLastArg(); for (int i=0; i<a.length; i++) a[i].setValue(v); in the "Variable[] fillArray()" method of the "ij.macro. Functions.java" file by: Variable v = getLastArg(); Arrays.fill(a, v); Which would then as well extend this method for strings using the following java method: https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#fill%28char%5B%5D,%20char%29 My best regards, Philippe -----Message d'origine----- De : ImageJ Interest Group [mailto:[hidden email]] De la part de Jan Eglinger Envoyé : mercredi 17 janvier 2018 09:30 À : [hidden email] Objet : Re: Issue on newArray macro function Hi Wayne, On 16.01.2018 21:20, Wayne Rasband wrote: > Your proposed fix for this bug is in the latest daily build (1.51u12). This bug is not limited to expressions with +,-,* or / For example, while the following works: a = newArray(2, acos(0.2), log(2)); these other lines throw exceptions: a = newArray(acos(0.2), log(2), 2); a = newArray(log(2), 2, acos(0.2)); Jan > >> Which means that is there is something else than "," after the first >> element it interprets the code as being a newArray(size). >> >> I guess the fix for this issue would be to replace the line >> >> if (next==STRING_CONSTANT || nextNext==',' >> >> || nextNext=='[' || next=='-' || next==PI) >> >> return initNewArray(); >> >> With >> >> if (next==STRING_CONSTANT || nextNext==',' || next==PI >> >> || nextNext=='[' || next=='+' || next=='-' || next=='*' || >> next=='/') >> >> return initNewArray(); >> >> Within the "Variable[] newArray" method in the " ij.macro. Functions.java" >> file. >> >> My best regards, >> >> Philippe > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Jan Eglinger
> On Jan 17, 2018, at 3:30 AM, Jan Eglinger <[hidden email]> wrote:
> > Hi Wayne, > > On 16.01.2018 21:20, Wayne Rasband wrote: >> Your proposed fix for this bug is in the latest daily build (1.51u12). > > This bug is not limited to expressions with +,-,* or / > > For example, while the following works: > > a = newArray(2, acos(0.2), log(2)); > > these other lines throw exceptions: > > a = newArray(acos(0.2), log(2), 2); > a = newArray(log(2), 2, acos(0.2)); This bug is fixed in today’s daily build (1.51u16). -wayne > >>> Which means that is there is something else than "," after the first element >>> it interprets the code as being a newArray(size). >>> >>> I guess the fix for this issue would be to replace the line >>> >>> if (next==STRING_CONSTANT || nextNext==',' >>> >>> || nextNext=='[' || next=='-' || next==PI) >>> >>> return initNewArray(); >>> >>> With >>> >>> if (next==STRING_CONSTANT || nextNext==',' || next==PI >>> >>> || nextNext=='[' || next=='+' || next=='-' || next=='*' || >>> next=='/') >>> >>> return initNewArray(); >>> >>> Within the "Variable[] newArray" method in the " ij.macro. Functions.java" >>> file. >>> >>> My best regards, >>> >>> Philippe -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |