Unexpected error with # and ternary operator
-
I've found that to get the size of an array which is element of an array, I have to parenthesize the array expression. That's no problem, and this displays "C=2" as expected:
var A = {{1,2}, {3,4}} ;var B = 0 var C = (exists(var.B) ? var.B : #(var.A[0])) echo "C="^var.C
However, remove the semicolon so that B is defined, and it seems like you should see "C=0", but instead you get:
Error: in file macro line 3 column 45: meta command: expected object model value or string after '#
(Incidentally missing the closing apostrophe; also, it seems like it should say "expected object model value, string, or array expression after '#'".)
Parenthesizing the # expression doesn't help. It seems to be a parsing error. Possibly failing to recognize the : as part of the ternary operator under some circumstances.
-
@DonStauffer Obvious workaround :
var A = {{1,2}, {3,4}} var B = 0 var D = #(var.A[0]) var C = exists(var.B) ? var.B : var.D) echo "C="^var.C
-
@DonStauffer which firmware version are you using, and are you using standalone mode or attached SBC? I just tested this, which is the same as your example with the brackets after # removed and it works for me:
var A = {{1,2}, {3,4}} ;var B = 0 var C = (exists(var.B) ? var.B : #var.A[0]) echo "C="^var.C
If I remove the semicolon from the second line then it also works. I am running 3.6.0-alpha.1 in standalone mode. The expression parsing code has not changed since 3.5.2. Maybe you are running in SBC mode?
-
@DonStauffer I have now reproduced this and created https://github.com/Duet3D/RepRapFirmware/issues/1020 and https://github.com/Duet3D/RepRapFirmware/issues/1021.